Please suggest something ----

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\tourtravel\index.php on line 14**

<?php
include 'header.php';
include 'slider.php';
?> <div class="container" > <div class="row"> <div class="col-sm-6"> <?php include 'tab.php' ?> </div> <div class="col-sm-6"> <?php
 include("config.php");
$q = mysqli_query($con,"select * from packages");
 while ($r = mysqli_fetch_array($q)) {
echo "<table>";
echo "<tr>";
echo"<td style='padding-right: 20px;'> <div class='albumDetail'> <a href='find_holiday.php?goto=Goa'><img   class='img-responsive imghover' src='upload/$r[1]' width='220' height='150'  > <span class='albumtitle'>Goa</span> </a> </div> </div> </td>";
echo"<td style='padding-right: 20px;'> <div class='albumDetail'> <a href='find_holiday.php?goto=Leh Ladakh'><img   class='img-responsive imghover' src='upload/$r[2]' width='220' height='150'  > <span class='albumtitle'>Leh Ladakh</span> </a> </div> </div> </td>";
 echo "</tr>";
  echo "<br/><br/><br/>";
 echo "<tr>";
echo"<td style='padding-right: 20px;'> <div class='albumDetail'> <a href='find_holiday.php?goto=Kerala'><img   class='img-responsive imghover' src='upload/$r[3]' width='220' height='150'  > <span class='albumtitle'>Kerala</span> </a> </div> </div> </td>";
 echo"<td style='padding-right: 20px;'> <div class='albumDetail'> <a href='find_holiday.php?goto=Sikkim'><img   class='img-responsive imghover' src='upload/$r[4]' width='220' height='150'  > <span class='albumtitle'>Sikkim</span> </a> </div> </div> </td>";
echo "</tr>";
echo "</table>"; }
?> </div> </div> </div> <br/><br/><br/> <?php
include 'footer.php';
?>

Recommended Answers

All 8 Replies

I'm not sure what you mean, rproffitt?

It looks like he's looping through each row in the result set generated from query $q, and saving the row in an array $r for the iteration of the loop. That's what I do as well.

Line 7's call can have an object oriented or procedural style. While it looks like he's doing that, the line does not look valid to me.

This is why I supplied a link to the documentation.

I'm assuming mysqli query is returning false, hence the boolean msg.

OK, here's the example for the object oriented method.

$query = "SELECT Name, CountryCode FROM City ORDER by ID LIMIT 3";
$result = $mysqli->query($query);

/* numeric array */
$row = $result->fetch_array(MYSQLI_NUM);

Line 7 in the OP's source is incorrect in my view as the $q is well, unexpected. Should be an int, not the result from line 6.

While I like the oop method, I can't see anything wrong with the procedural code other than I'd enclose the whole thing in a conditional. As in if($q =....)

Then again if line 6 fails so will 7. OP needs to test for that.

That was my point. I believe Line 6 is returning 'false'. From the manual on mysqli_query:

Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.

The OP is running a SELECT query so he/she either gets a result object or FALSE.

So I'm assuming $q is set to FALSE, and therefore cannot be a valid parameter for line 7. This is my rationale for using a conditional...

if($q = mysqli_query($con,"select * from packages")){
     while ($r = mysqli_fetch_array($q)) {
     ..etc..
     }
}else{
    echo "Failed";
}

You could also use try/catch.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.