Reputation: 217
Warning: I am quite new to php I tried to loop using an integer i but for some reason it is empty, when I output it I get "i=" and it is "empty" I guess, any help would be great, below is the loops I am trying to run it in.
First loop (The item turns up empty also)
for($i = 0; $i < $size; $i++){
$sql = "SELECT Aisle FROM `Items` WHERE `Store_ID` = $storeid AND `Name`= '$items[$i]'";
print($i);
$result= mysql_query($sql, $link);
if($result){
//print("sql ran");
print("$sql");
}
Second Loop
for($i = 0; $i < count($aisles); $i++){
if($aisles[$i] == null){
$aisles[$i] = 'Item Not Found';
}
echo json_encode($aisles[$i]);
}
Upvotes: 1
Views: 40
Reputation: 32232
You cannot refer to array indexes inside quoted strings like that, change your query string to:
$sql = "SELECT Aisle FROM `Items` WHERE `Store_ID` = $storeid AND `Name`= '{$items[$i]}'";
Also, do yourself a favor and learn PDO or MySQLi instead of mysql_* functions.
Upvotes: 1