1

I know this question looks like repeated, but I really read a lot but doesn't solve the problem.

I want to echo the last 10 rows in sql and I get this error.

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\rock\fyp\postAdv.php on line 10

THE Event: 

THE Date:

THE Time:

THE Venue:

Note:

the php file is

<?php
$con=mysqli_connect("rock","mido","1234","fyp");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
 $start = 10;
 $result = mysqli_query($con,"SELECT * FROM event ORDER BY ID DESC LIMIT $start,10");
  $row = mysqli_fetch_array($result) ;

 {

  echo "<br><h4> " . "THE Event:  " . $row['EventName'] . "</br>";
  echo "<h4>" . "THE DATE:  " . $row['Date'] ;
  echo "<h4>" . "THE TIME:  " . $row['Time'] ;
  echo "<h4>" . "THE Venue:  " . $row['Venue'] ;
  echo "<h4>" . "Note:  " . $row['Note'] ;

  }

mysqli_close($con);
?>
Dharman
  • 30,962
  • 25
  • 85
  • 135
opa.mido
  • 45
  • 1
  • 1
  • 8
  • 3
    You didn't initialize `$start` anywhere. Thus your query fails. – Shankar Narayana Damodaran Mar 18 '14 at 17:35
  • Since you only want the last 10, remove `$start,` so it is just `LIMIT 10`. If you are going to paginate in the future, leave it in, but initialize it before your query -> `$start = 0` – Sean Mar 18 '14 at 17:50
  • done initialize `$start` the result its show me only where the start is – opa.mido Mar 18 '14 at 17:51
  • Change `$row = mysqli_fetch_array($result) ;` to `while($row = mysqli_fetch_array($result))` as right now you are only returning 1 row with `mysqli_fetch_array()`, where you want to loop through each `mysqli_fetch_array()` in a `while()` loop – Sean Mar 18 '14 at 17:53
  • @sean I changed but the result went blank. nothing even the echo – opa.mido Mar 18 '14 at 18:02
  • Then you most likely have a syntax error. Make sure that it is `while($row = mysqli_fetch_array($result)) { echo ...`. Make sure there is not a semi colon `;` between the closing `)` and the opening `{` – Sean Mar 18 '14 at 19:06
  • This error happened for me when when I was connecting to wrong data base, the connection was successful but the tables were not there. – Mukesh Nov 15 '14 at 13:58

2 Answers2

3

$result is a boolean because the query you are executing is failing! A failed query gives off boolean 'false'.

Check you query. Try setting $start with a value before using it in your query.

arijeet
  • 1,858
  • 18
  • 26
0

Set $start = 1 before your query try again.

$start = 1;
Caimen
  • 2,623
  • 2
  • 26
  • 43