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

Unknown column in field list PHP/MySQL

Guest
Jun 07, 2010 Jun 07, 2010

I have created a feedback form for our airshow website and it's working fine. I am now creating some review pages, which are also working fine, so

...I decided to improve one of the review pages and now it doesn't work...sigh.

We ask the responders to provide their zip code and I have a view showing the number of responses by zip code, this works fine and can be seen here http://www.hollisterairshow.com/feedback-results.php , so I decided to improve this by adding the city/ state based on zip code. I created a new table called 'zipcodes' and imported a list of zip codes and city/ state info - all 42,000+ of them.

The PHP/MySQL which works is shown below

<?php
// Make a MySQL Connection

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

// Print out result
while($row = mysql_fetch_array($result)){
echo $row['zip']. " ". $row['COUNT(zip)'];
echo "<br />";
}
?>

As I am now dealing with two tables I thought I needed to add the table name to any field so I added table names and the fields for the new table so

I changed the PHP/ MySQL as follows

<?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['feedback.zip']. " ". $row['COUNT(feedback.zip)']. " ". $row['zipcodes.citystate'];
echo "<br />";
}
?>

and it fails when I run it saying "Unknown column 'feedback.zip' in 'field list' "

I'd appreciate any suggestions on this, I'm new to this PHP/MySQL stuff.

Thanks,

Tony

TOPICS
Server side applications
3.9K
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 , Jun 07, 2010 Jun 07, 2010

Tables listed in the From clause need to be comma seperated. As it is, it is being evaluated as an alias.

Translate
Guest
Jun 07, 2010 Jun 07, 2010

Why do you use a dot in your tables names?. It could be that .zip is a reserved MySQL extension.

Try using underscores to name your tables.

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
LEGEND ,
Jun 07, 2010 Jun 07, 2010
LATEST

>Why do you use a dot in your tables names?

The dot is the standard qualification seperator. It is required if you are qualifying the column with the table name.

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
LEGEND ,
Jun 07, 2010 Jun 07, 2010

Tables listed in the From clause need to be comma seperated. As it is, it is being evaluated as an alias.

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