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. 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']; } 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 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. 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 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 } 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 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 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
Archived
This topic is now archived and is closed to further replies.