spacepoet Posted February 10, 2011 Share Posted February 10, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/227230-having-trouble-with-select/ Share on other sites More sharing options...
jamesjmann Posted February 10, 2011 Share Posted February 10, 2011 Which line is '29'? Quote Link to comment https://forums.phpfreaks.com/topic/227230-having-trouble-with-select/#findComment-1172147 Share on other sites More sharing options...
btherl Posted February 10, 2011 Share Posted February 10, 2011 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 ")" Quote Link to comment https://forums.phpfreaks.com/topic/227230-having-trouble-with-select/#findComment-1172150 Share on other sites More sharing options...
spacepoet Posted February 10, 2011 Author Share Posted February 10, 2011 $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? Quote Link to comment https://forums.phpfreaks.com/topic/227230-having-trouble-with-select/#findComment-1172176 Share on other sites More sharing options...
btherl Posted February 10, 2011 Share Posted February 10, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/227230-having-trouble-with-select/#findComment-1172178 Share on other sites More sharing options...
spacepoet Posted February 10, 2011 Author Share Posted February 10, 2011 OK, I have a tutorial I just found for pagination .. I will see how it goes. Thanks for the tips! Quote Link to comment https://forums.phpfreaks.com/topic/227230-having-trouble-with-select/#findComment-1172180 Share on other sites More sharing options...
jamesjmann Posted February 12, 2011 Share Posted February 12, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/227230-having-trouble-with-select/#findComment-1173140 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.