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.

 

Link to comment
Share on other sites

 

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. 

Edited by jas21
Link to comment
Share on other sites

 

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
}
Link to comment
Share on other sites

 

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

Edited by jas21
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.