Hooch Posted February 6, 2010 Share Posted February 6, 2010 Hey all.How do I have multiple conditions in an if loop?Example...I have this query $sql = "SELECT * FROM `table1` ORDER BY `field` ASC"; $result = mysql_query($sql); I want the array from that query to the following loop... if($_GET['tab'] == 3 && ($_GET['t2'] == 'array[0]' || $_GET['t2'] == 'array[1]' || $_GET['t2'] == 'array[3]' || etc )) { Now the query will have a dynamic number of entries, it will vary.Thank you for your time. Link to comment Share on other sites More sharing options...
jeffman Posted February 6, 2010 Share Posted February 6, 2010 If you plan to search the whole array, would this help: http://www.php.net/manual/en/function.in-array.php Link to comment Share on other sites More sharing options...
Hooch Posted February 6, 2010 Author Share Posted February 6, 2010 Thank man!I did do some research on the site...but I'm having a hard time getting the for loop correct.I'm not sure if this will help, but I wanted to get the array printed out.Here is what I have so far... //Count the number of entries in the Category Table $query = "SELECT COUNT(*) as num FROM `cat1`"; $total = mysql_fetch_array(mysql_query($query)); $total = ($total['num'] - 1); $tabs = mysql_query("SELECT * FROM `cat1` ORDER BY `cat1` ASC"); $var = array(); while ($getTabs = mysql_fetch_assoc($tabs)) $var[] = $getTabs["tab"]; //echo implode(",", $var); for ( $i = 0; $i <= $total; $i++ ) { echo $var[$i]; echo '<br>'; } Now I need to get that array into... if($_GET['tab'] == 3 && ($_GET['t2'] == 'array[0]' || $_GET['t2'] == 'array[1]' || $_GET['t2'] == 'array[3]' || etc )) { Don't forget that array changes in results. It might have 5 or 30 entries. My head is hurting Link to comment Share on other sites More sharing options...
Synook Posted February 6, 2010 Share Posted February 6, 2010 Err, an if block isn't a loop. Maybe you are thinking of something like this? if($_GET['tab'] == 3 && in_array($_GET['t2'], $var)) Link to comment Share on other sites More sharing options...
Hooch Posted February 6, 2010 Author Share Posted February 6, 2010 Thanks guys.A combined effort has fixed the problem.Synook your reply cured my headache.Thank you kindly! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.