Forum Moderators: coopster
fruits (2 fields - fruitname & description)
fruitname ¦ description
banana ¦ banana description here
mango ¦ mango description here
apple ¦ apply description here
orange ¦ orange description here
pineapple ¦ pineapple description here
guava ¦ guava description here
melon ¦ melon description here$mystring = banana, mango, apple, pineapple, orange
$show_all_fruits = explode(",",$mystring );
for($i=0; $i < sizeof($show_all_fruits); $i++) {
$query_fruit = "SELECT * FROM fruits WHERE fruitname = '".$show_all_fruits[$i]."'";
$fruit_result = mysql_query($query_fruit) or die(mysql_error());
if (mysql_num_rows($fruit_result) > 0) {
$row_fruit = mysql_fetch_row($fruit_result);
echo $row_fruit[1];
}
}
Im sure that all the listed fruit in
$mystring exist in the table but it always found only 1 record - the first one (banana). Further test shows that after executing the first query it will return 0 record for the succeeding query in the loop even though the fruit name exist in the table
Whats wrong with my query / for loop? Thanks