jas21 Posted January 5, 2014 Share Posted January 5, 2014 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. Any help is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/285105-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result/ Share on other sites More sharing options...
Ch0cu3r Posted January 5, 2014 Share Posted January 5, 2014 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']; } Quote Link to comment https://forums.phpfreaks.com/topic/285105-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result/#findComment-1463906 Share on other sites More sharing options...
jas21 Posted January 5, 2014 Author Share Posted January 5, 2014 (edited) 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 January 5, 2014 by jas21 Quote Link to comment https://forums.phpfreaks.com/topic/285105-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result/#findComment-1463915 Share on other sites More sharing options...
Ch0cu3r Posted January 5, 2014 Share Posted January 5, 2014 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 } Quote Link to comment https://forums.phpfreaks.com/topic/285105-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result/#findComment-1463928 Share on other sites More sharing options...
jas21 Posted January 5, 2014 Author Share Posted January 5, 2014 (edited) 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 January 5, 2014 by jas21 Quote Link to comment https://forums.phpfreaks.com/topic/285105-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result/#findComment-1463951 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.