msininism Posted May 11, 2007 Share Posted May 11, 2007 i couldn't think of another way to word the title. this is what i want to do. im building a small database driven website with php 5 and mysql. the database will have the following columns, first name, last name, address, city, state, zip, email, website. on the side of the webpage, ill list the states (arkansas, nevada, etc...) each name has a link like states.php?pick=alaska , states.php?pick=south_carolina, etc.... i want the states.php page to list on the rows that contain the same state as the one chosen. im lost as to how to do this. my best guess is to have the query line read $query = "SELECT first_name, last_name, address1, address2, city, state, zip, phone, website FROM clients WHERE state IS ??? "; i don't know what to put where those questions marks are. for example. if someone clicks nevada, they go to states.php?pick=nevada. when they get to states.php, the entries show up with only nevada listings. i can get it so if i had the right query line, i could get the page to output the entries, i just don't know how to narrow down the entries to one state. can somebody please point me in the right direction? Thankyou -ross Quote Link to comment https://forums.phpfreaks.com/topic/50959-trouble-with-a-flexible-query/ Share on other sites More sharing options...
micah1701 Posted May 11, 2007 Share Posted May 11, 2007 $state = $_GET['pick']; $query = "SELECT first_name, last_name, address1, address2, city, state, zip, phone, website FROM clients WHERE state ='$state' "; Quote Link to comment https://forums.phpfreaks.com/topic/50959-trouble-with-a-flexible-query/#findComment-250715 Share on other sites More sharing options...
taith Posted May 11, 2007 Share Posted May 11, 2007 $_GET[pick] Quote Link to comment https://forums.phpfreaks.com/topic/50959-trouble-with-a-flexible-query/#findComment-250716 Share on other sites More sharing options...
msininism Posted May 11, 2007 Author Share Posted May 11, 2007 thank you for the help. i swear im not usually this inept, but i have another problem that is bothering me. the statement $state = $_GET['pick']; $query = "SELECT first_name, last_name, address1, address2, city, state, zip, phone, website FROM clients WHERE state='$state' "; worked fine, but my problem is that the pick and the state aren't going to be the same. to save database room, i have all of the entries in the state column down to two characters. so if alabama is the pick and then becomes the state variable in the query, nothing will come up because it won't match up with anything in the database. i thought of changing all the links to states.php?pick=AL or AK or SC or whatnot, but then the header that appears at every page will be an abbreviation. so some bit of coding must be done. i tried conditionals, but i can't think of how to get them to work. i've tried several combinations, and what happens is that my window goes blank or it accepts all the conditionals at once. this is what im looking to accomplish ------------------------------------ $pick= $_GET['pick'] /////////////////// if pick is alabama, then AL = $state and 'Alabama' = $header if pick is south_carolina, then SC = $state and 'South Carolina' = $header if pick is new_york, then NY = $state and 'New York' = $header ////////////////// $query = "SELECT first_name, last_name, address1, address2, city, state, zip, phone, website FROM clients WHERE state='$state' "; $result = @mysql_query ($query); $num = mysql_num_rows($result); in a nutshell, the pick becomes an abbreviation to be used in database searching and one or two words with the first letter of each capitalized for header purposes. thank you rosssssss Quote Link to comment https://forums.phpfreaks.com/topic/50959-trouble-with-a-flexible-query/#findComment-250862 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.