mpharo Posted April 13, 2007 Share Posted April 13, 2007 I have the following code... $category is an array generated from a previous query which has different amounts.... for ($i=0;$i<=count($category);$i++) { $select2=mysql_query("SELECT * FROM traffic WHERE category LIKE '%$category[$i]%'") or die(mysql_error()); $total=0; while($sql2=mysql_fetch_array($select2)){ $total++; } } does anyone know of another way I can take each element in an array and use it for a query other than this?? Quote Link to comment Share on other sites More sharing options...
craygo Posted April 13, 2007 Share Posted April 13, 2007 What do you want to return?? you can also use <?php foreach($category as $cat){ $select2=mysql_query("SELECT * FROM traffic WHERE category LIKE '%$cat%'") or die(mysql_error()); $total=0; while($sql2=mysql_fetch_array($select2)){ $total++; } } >? Not sure what $total is for but not needed in either script unless you are adding up some values. Ray Quote Link to comment Share on other sites More sharing options...
mpharo Posted April 13, 2007 Author Share Posted April 13, 2007 the foreach worked great...thanks for your help... Quote Link to comment 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.