C
ckcook17
Guest
I'm trying to make a loop to print the results of 22 MYSQL queries. The MYSQL results are arrays. I know for a fact that the results are not null but when I put them in the array and call $resultarray[$j] it always says it is null.
My code is:
$item = htmlspecialchars($_POST['item']); //input from a form on a previous page
$result1 = mysql_query("SELECT * FROM `shelf 1` WHERE Item REGEXP '.*$item.*'");
$result2 = mysql_query("SELECT * FROM `shelf 2` WHERE Item REGEXP '.*$item.*'");
$result3 = mysql_query("SELECT * FROM `shelf 3` WHERE Item REGEXP '.*$item.*'");
$result4 = mysql_query("SELECT * FROM `shelf 4` WHERE Item REGEXP '.*$item.*'");
$result5 = mysql_query("SELECT * FROM `shelf 5` WHERE Item REGEXP '.*$item.*'");
$result6 = mysql_query("SELECT * FROM `shelf 6` WHERE Item REGEXP '.*$item.*'");
$result7 = mysql_query("SELECT * FROM `shelf 7` WHERE Item REGEXP '.*$item.*'");
$result8 = mysql_query("SELECT * FROM `shelf 8` WHERE Item REGEXP '.*$item.*'");
$result9 = mysql_query("SELECT * FROM `shelf 9` WHERE Item REGEXP '.*$item.*'");
$result10 = mysql_query("SELECT * FROM `shelf 10` WHERE Item REGEXP '.*$item.*'");
$result11 = mysql_query("SELECT * FROM `shelf 11` WHERE Item REGEXP '.*$item.*'");
$result12 = mysql_query("SELECT * FROM `shelf 12` WHERE Item REGEXP '.*$item.*'");
$result13 = mysql_query("SELECT * FROM `shelf 13` WHERE Item REGEXP '.*$item.*'");
$result14 = mysql_query("SELECT * FROM `shelf 14` WHERE Item REGEXP '.*$item.*'");
$result15 = mysql_query("SELECT * FROM `shelf 15` WHERE Item REGEXP '.*$item.*'");
$result16 = mysql_query("SELECT * FROM `shelf 16` WHERE Item REGEXP '.*$item.*'");
$result17 = mysql_query("SELECT * FROM `shelf 17` WHERE Item REGEXP '.*$item.*'");
$result18 = mysql_query("SELECT * FROM `shelf 18` WHERE Item REGEXP '.*$item.*'");
$result19 = mysql_query("SELECT * FROM `shelf 19` WHERE Item REGEXP '.*$item.*'");
$result20 = mysql_query("SELECT * FROM `shelf 20` WHERE Item REGEXP '.*$item.*'");
$result21 = mysql_query("SELECT * FROM `shelf 21` WHERE Item REGEXP '.*$item.*'");
$result22 = mysql_query("SELECT * FROM `shelf 22` WHERE Item REGEXP '.*$item.*'");
$resultarrary = array($result1, $result2, $result3, $result4, $result5, $result6, $result7, $result8, $result9, $result10, $result11, $result12, $result13, $result14, $result15, $result16, $result17, $result18, $result19, $result20, $result21, $result22);
$j=0;
//all of result array is coming up null
while($j <= 21)
{
if($resultarray[$j]==null) //this currently is true 22 times. Yet if($result11==null) is false.
{
echo("Hai");
$j++;
continue;
}
echo("I'm in here");
$num=mysql_numrows($resultarray[$j]);
$i=0;
while($i < $num)
{
$printitem=mysql_result($resultarray[$j], $i, "Item");
$printamount=mysql_result($resultarray[$j], $i, "Amount");
$printcategory=mysql_result($resultarray[$j], $i, "Category");
echo "Item: $printitem, Amount: $printamount, Category: $printcategory<br>";
$i++;
}
$j++;
}
I know that the MYSQL commands work perfectly. The thing you are seeing isn't single quotes, it is the "quote thing" on the same button as ~.
Thanks for the advice.
Wow that typo was the entirety of my problem. I stated at it for sooooo long and it was a typo. Thank you very much.
My code is:
$item = htmlspecialchars($_POST['item']); //input from a form on a previous page
$result1 = mysql_query("SELECT * FROM `shelf 1` WHERE Item REGEXP '.*$item.*'");
$result2 = mysql_query("SELECT * FROM `shelf 2` WHERE Item REGEXP '.*$item.*'");
$result3 = mysql_query("SELECT * FROM `shelf 3` WHERE Item REGEXP '.*$item.*'");
$result4 = mysql_query("SELECT * FROM `shelf 4` WHERE Item REGEXP '.*$item.*'");
$result5 = mysql_query("SELECT * FROM `shelf 5` WHERE Item REGEXP '.*$item.*'");
$result6 = mysql_query("SELECT * FROM `shelf 6` WHERE Item REGEXP '.*$item.*'");
$result7 = mysql_query("SELECT * FROM `shelf 7` WHERE Item REGEXP '.*$item.*'");
$result8 = mysql_query("SELECT * FROM `shelf 8` WHERE Item REGEXP '.*$item.*'");
$result9 = mysql_query("SELECT * FROM `shelf 9` WHERE Item REGEXP '.*$item.*'");
$result10 = mysql_query("SELECT * FROM `shelf 10` WHERE Item REGEXP '.*$item.*'");
$result11 = mysql_query("SELECT * FROM `shelf 11` WHERE Item REGEXP '.*$item.*'");
$result12 = mysql_query("SELECT * FROM `shelf 12` WHERE Item REGEXP '.*$item.*'");
$result13 = mysql_query("SELECT * FROM `shelf 13` WHERE Item REGEXP '.*$item.*'");
$result14 = mysql_query("SELECT * FROM `shelf 14` WHERE Item REGEXP '.*$item.*'");
$result15 = mysql_query("SELECT * FROM `shelf 15` WHERE Item REGEXP '.*$item.*'");
$result16 = mysql_query("SELECT * FROM `shelf 16` WHERE Item REGEXP '.*$item.*'");
$result17 = mysql_query("SELECT * FROM `shelf 17` WHERE Item REGEXP '.*$item.*'");
$result18 = mysql_query("SELECT * FROM `shelf 18` WHERE Item REGEXP '.*$item.*'");
$result19 = mysql_query("SELECT * FROM `shelf 19` WHERE Item REGEXP '.*$item.*'");
$result20 = mysql_query("SELECT * FROM `shelf 20` WHERE Item REGEXP '.*$item.*'");
$result21 = mysql_query("SELECT * FROM `shelf 21` WHERE Item REGEXP '.*$item.*'");
$result22 = mysql_query("SELECT * FROM `shelf 22` WHERE Item REGEXP '.*$item.*'");
$resultarrary = array($result1, $result2, $result3, $result4, $result5, $result6, $result7, $result8, $result9, $result10, $result11, $result12, $result13, $result14, $result15, $result16, $result17, $result18, $result19, $result20, $result21, $result22);
$j=0;
//all of result array is coming up null
while($j <= 21)
{
if($resultarray[$j]==null) //this currently is true 22 times. Yet if($result11==null) is false.
{
echo("Hai");
$j++;
continue;
}
echo("I'm in here");
$num=mysql_numrows($resultarray[$j]);
$i=0;
while($i < $num)
{
$printitem=mysql_result($resultarray[$j], $i, "Item");
$printamount=mysql_result($resultarray[$j], $i, "Amount");
$printcategory=mysql_result($resultarray[$j], $i, "Category");
echo "Item: $printitem, Amount: $printamount, Category: $printcategory<br>";
$i++;
}
$j++;
}
I know that the MYSQL commands work perfectly. The thing you are seeing isn't single quotes, it is the "quote thing" on the same button as ~.
Thanks for the advice.
Wow that typo was the entirety of my problem. I stated at it for sooooo long and it was a typo. Thank you very much.