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
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 ")"

Link to comment
Share on other sites

$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?

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.