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?? Link to comment https://forums.phpfreaks.com/topic/46894-solved-array-for-insert/ 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 Link to comment https://forums.phpfreaks.com/topic/46894-solved-array-for-insert/#findComment-228614 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... Link to comment https://forums.phpfreaks.com/topic/46894-solved-array-for-insert/#findComment-228621 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.