Jump to content

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result


jas21

Recommended Posts

Hello Experts,

 

                             I am stuck in database query. Well i am making a page which retrieve my database value. Below is my code:

<?php  
$con=mysqli_connect("localhost","root","","test");  
if (mysqli_connect_errno())  
{  
echo "Failed to connect to MySQL: " . mysqli_connect_error();  
} 

$result = mysqli_query($con,"SELECT * FROM testing where flag=1 "); 

foreach ($result as $results){ 

while($row = mysqli_fetch_array($results))  
{  
echo  $row['review'] ; 
echo  $row['name'] ; 
}  
} 
mysqli_close($con);  
?>

When i run the above code it shows me error:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, array given in /home/stradsol/public_html/test1.php on line 14  

I am stuck. I dont know what I am missing. :(  :sweat: 

Any help is appreciated.

 

  On 1/5/2014 at 11:04 AM, Ch0cu3r said:

 

Remove the foreach loop. You need to pass $result to mysqli_fetch_array

while($row = mysqli_fetch_array($result))  
{  
   echo  $row['review']; 
   echo  $row['name']; 
} 

 

Yes, you are exactly right. I tried it and it works perfect. But i have use some css "quotes" design in each of records. 

My css designed code are been pasted below:


<?php  
$con=mysqli_connect("localhost","root","","test");  
if (mysqli_connect_errno())  
{  
echo "Failed to connect to MySQL: " . mysqli_connect_error();  
} 


$result = mysqli_query($con,"SELECT * FROM testing where flag=1 "); 

foreach ($result as $results){ 
echo "<div class=\"testimonial\">"; 
while($row = mysqli_fetch_array($results, MYSQL_BOTH))  
{  

echo  $row['review'] ; 
echo "<div class=\"arrow-down\">"; 
echo "</div>"; 
echo "<div class=\"testimonial-author\">"; 
echo  $row['name'] ; 
echo "</div>"; 
}  

echo "</div>"."<br>"; 

} 


mysqli_close($con);  
?>

So, now what am i missing... I am really stuck. 

  Quote

 

But i have use some css "quotes" design in each of records.

Then open/close the testimonial div within the while loop instead

while($row = mysqli_fetch_array($results, MYSQL_BOTH))  
{  
echo "<div class=\"testimonial\">"; # open testimonial
echo  $row['review'] ; 
echo "<div class=\"arrow-down\">"; 
echo "</div>"; 
echo "<div class=\"testimonial-author\">"; 
echo  $row['name'] ; 
echo "</div>"; 
echo "</div>"."<br>"; # close testimonial
}
  On 1/5/2014 at 4:26 PM, Ch0cu3r said:

 

Then open/close the testimonial div within the while loop instead

while($row = mysqli_fetch_array($results, MYSQL_BOTH))  
{  
echo "<div class=\"testimonial\">"; # open testimonial
echo  $row['review'] ; 
echo "<div class=\"arrow-down\">"; 
echo "</div>"; 
echo "<div class=\"testimonial-author\">"; 
echo  $row['name'] ; 
echo "</div>"; 
echo "</div>"."<br>"; # close testimonial
}

 

Thanks so much. Its working great. Thanks a lot

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.