Jump to content

Having trouble with SELECT


spacepoet

Recommended Posts

Hi:

 

I'm having trouble getting my data to display using SELECT.

 

Maybe someone can point out what I'm missing.

 

I want to display the City and Zip for all 50 states, depending on which abbr_state name is clicked.

 

This my code:

<a href="z.php?abbr_state=NY">New York</a>
<br />
<a href="z.php?abbr_state=PA">Pennsylvania</a>

<?php

include('include/myConn.php');

$result = mysql_query("SELECT city,abbr_state,zip FROM `zip_codes` WHERE `abbr_state` = " . mysql_real_escape_string ( $_GET['abbr_state'] );")

while($row = mysql_fetch_array($result)){
echo $row['city']. " - ". $row['zip'];
echo "<br />";
}

?>

 

Getting this error:

Parse error: syntax error, unexpected ';' in /var/www/domains/sppcon.com/docs/z.php on line 29

 

What am I missing? The only ';' I see is at the end but removing it doesn't fix the error.

 

Also - now that I think of it - how would I list the Cities in alphabetical order, and perhaps do pagination to I only show a certain amount each page?

 

There are a lot of cities and I think displaying them all on one page would be a bit much.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/227230-having-trouble-with-select/
Share on other sites

Try this:

 

$result = mysql_query("SELECT city,abbr_state,zip FROM `zip_codes` WHERE `abbr_state` = '" . mysql_real_escape_string ( $_GET['abbr_state'] ) . "'");

 

I'm a postgres user, so no guarantees it'll work..

 

Edit: Fixed misplaced ")"

$result = mysql_query("SELECT city,abbr_state,zip FROM `zip_codes` WHERE `abbr_state` = '" . mysql_real_escape_string ( $_GET['abbr_state'] ) . "'");

 

WAS PERFECT!

 

Thanks for the help!

 

Any ideas how to turn this into a multi-column display with pagination?

 

Like:

Item 1  Item 5  Item 9
Item 2  Item 6  Item 10
Item 3  Item 7  Item 11
Item 4  Item 8  Item 12

1 | 2 | 3 | 4 | 5

 

Etc..

 

Something like that?

Pagination is a big job .. I can only suggest you look at a tutorial, and post here if you get stuck.  As for multi-column, you can have a variable which counts which column you are up to, and outputs different html if you have reached the end of a row.  You might also need to use a table to make it look nice, as you need to think about alignment of the columns.

 

 

OK, I have a tutorial I just found for pagination .. I will see how it goes.

 

Thanks for the tips!

 

You know there's a tutorial for pagination right here on phpfreaks. I highly recommend this one because it was very easy to understand and worked for me!

http://www.phpfreaks.com/tutorial/basic-pagination

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.