Reputation: 719
I have a SQL query which I'm executing through php. The query results are being displayed correctly.
What am I doing wrong here?? Instead of displaying the results I want to store them in an array and display them later in the below while
loop.
$arr = array();
$sql = "SELECT itemName,itemRating from $userName WHERE itemName IN ( SELECT itemName from $user )";
$result = $conn->query($sql);
$i=0;
if($result)
{
while($row1=mysqli_fetch_row($result))
{
//echo $row1[0]." ".$row1[1]."<br>";
arr[$i]=$row1[0]; //Line 40
$i++;
}
}
$j=0;
while($j < $i)
{
echo $arr[$j];
$j++;
}
Error:
Parse error: syntax error, unexpected '=' in /opt/lampp/htdocs/Project/calculateSimilarity.php on line 40
Upvotes: 0
Views: 51
Reputation: 2753
hope it help..
$arr=array();
$sql="SELECT itemName,itemRating from $userName WHERE itemName IN ( SELECT itemName from $user )";
$result=$conn->query($sql);
$i=0;
if($result)
{
while($row1=mysqli_fetch_row($result))
{
array_push($arr,$row1[$i]); //Line 40
$i++;
}
}
$j=0;
while($j<$i)
{
echo $arr[$j];
$j++;
}
Upvotes: 1
Reputation: 2786
You have forgotten the $ dollar sign in front
change:
arr[$i]=$row1[0]; //Line 40
to:
$arr[$i]=$row1[0]; //Line 40
Upvotes: 1