netpants Posted November 2, 2007 Share Posted November 2, 2007 I need to know how to write an if statement. For example I have a form dropdown called Cook, and Kendall, if someone selects Cook it will look in a certain table in the database, or if someone chooses Kendall it will look in a different table. Heres what I have currently it only works from one table. $result = mysql_query("SELECT * FROM coords WHERE city='$city' AND county='$county' AND street='$street'") What do I need to put in there for the if statement to say if $county == Cook then search in a different table that I will create. I will eventually have 7 different counties I will need to put if statements for. Quote Link to comment https://forums.phpfreaks.com/topic/75805-solved-if-statement-help-please/ Share on other sites More sharing options...
fenway Posted November 2, 2007 Share Posted November 2, 2007 You can't use expression to determine which table to query... you'll have to do that in the application code. Quote Link to comment https://forums.phpfreaks.com/topic/75805-solved-if-statement-help-please/#findComment-383682 Share on other sites More sharing options...
netpants Posted November 2, 2007 Author Share Posted November 2, 2007 so the easiest thing to do would be to create a different form for eatch of the counties? Quote Link to comment https://forums.phpfreaks.com/topic/75805-solved-if-statement-help-please/#findComment-383685 Share on other sites More sharing options...
fenway Posted November 2, 2007 Share Posted November 2, 2007 No, the easiest thing would be to have a single table for all counties with a county_id field. What I was talking about was having a switch or if/else blocks to specify a PHP variable with the table. Quote Link to comment https://forums.phpfreaks.com/topic/75805-solved-if-statement-help-please/#findComment-383687 Share on other sites More sharing options...
netpants Posted November 2, 2007 Author Share Posted November 2, 2007 There are eventually going to be over 91,000 entries into the database, so I thought by dividing it up into different tables it would make it a little faster when someone searches the database. Eatch of the counties has its own field, there is a field called county in my table. Quote Link to comment https://forums.phpfreaks.com/topic/75805-solved-if-statement-help-please/#findComment-383689 Share on other sites More sharing options...
fenway Posted November 2, 2007 Share Posted November 2, 2007 There are eventually going to be over 91,000 entries into the database, so I thought by dividing it up into different tables it would make it a little faster when someone searches the database. Eatch of the counties has its own field, there is a field called county in my table. 91K isn't enough to make it worthwhile. Quote Link to comment https://forums.phpfreaks.com/topic/75805-solved-if-statement-help-please/#findComment-383699 Share on other sites More sharing options...
netpants Posted November 2, 2007 Author Share Posted November 2, 2007 Great, thanks then I think what I have already will work just fine then. Quote Link to comment https://forums.phpfreaks.com/topic/75805-solved-if-statement-help-please/#findComment-383712 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.