Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How do I display an invalid zip code in a summary table

Guest
May 06, 2012 May 06, 2012

On my airshow website we have a feedback form, one of the questions is the zipcode where the visitor came from. This works fine. The summary results tab includes a lookup for the zipcode where I show the city associated with the zipcode and then how many responses came from that zipcode. This can be seen here http://www.hollisterairshow.com/feedback-results.php?tab=7

In testing, I found that an invalid zipcode is not displayed in the summary table, although it is counted in the total number of responses. I'd like to display the invalid zipcode and leave the City blank, or maybe put "Invalid zip code". The current code is displayed below, it's beyond my ability to figure out how I should change it to display invalid zipcodes and I'd really appreciate some direction on this.

I know I could validate the zipcode on entry but it's quite possible the zipcode table I have is out of date and i can't find a free downloadable list, so I'm thinking anything invalid could cause me to update my table.which is fine.

Thanks for any assistance.

Tony

<div class="TabbedPanelsContent">

<?php


// Make a MySQL Connection

$query = "SELECT feedback.zip, COUNT(feedback.zip), zipcodes.citystate FROM feedback, zipcodes WHERE feedback.zip = zipcodes.zipcode GROUP BY feedback.zip";
 
$result = mysql_query($query) or die(mysql_error());

// Print out result

while($row = mysql_fetch_array($result))

{
echo $row['zip']. " ". $row['COUNT(feedback.zip)']. " ". $row['citystate'];
echo "<br />";
}
?>

</div>

TOPICS
Server side applications
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 07, 2012 May 07, 2012

Use an outer join on the two tables so that results are returned for all feedback rows, instead of just matching rows. The column zipcodes.citystate will be NULL. In your recordset output, you can test for null in the column and populate it with "Invalid Zipcode" if you want.

You'll need to move the join to the FROM clause as I believe that MySQL does not support outer joins in the WHERE clause like most other DBMS's.

Translate
LEGEND ,
May 07, 2012 May 07, 2012

Use an outer join on the two tables so that results are returned for all feedback rows, instead of just matching rows. The column zipcodes.citystate will be NULL. In your recordset output, you can test for null in the column and populate it with "Invalid Zipcode" if you want.

You'll need to move the join to the FROM clause as I believe that MySQL does not support outer joins in the WHERE clause like most other DBMS's.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 24, 2012 May 24, 2012
LATEST

You're right that's exactly what I need to do, I had never heard of a LEFT JOIN. Thank you again. Now all I need to do is figure out the syntax.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines