Copy link to clipboard
Copied
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>
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more