0

Really simple question but I can't seem to find a solution on here that works. I have a database with rows id, user, message and time. I currently only have one row, but I'd like to be able to print all rows.

$query = "SELECT * FROM 'wisp_posts'";
$result = mysqli_query($con, $query);

while ($row = mysqli_fetch_array($result)) {
    echo $row['user'];
}

The error I get is:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given

Which I know means that it's returning False.

Sebastian
  • 3,442
  • 18
  • 56
  • 93

5 Answers5

3

You have to remove the single quotes ' and substitute them with backticks ` (that could be optional)

You should write your query as:

$query = "SELECT * FROM `wisp_posts`";

Or simpler:

$query = "SELECT * FROM wisp_posts";
Funk Forty Niner
  • 74,372
  • 15
  • 66
  • 132
Ruben Giaquinto
  • 381
  • 1
  • 14
0

It means, that that you have an error in your query, look: http://de1.php.net/mysqli_query

You can read errors with this method: http://www.php.net/manual/de/mysqli.error.php

schnawel007
  • 3,848
  • 3
  • 16
  • 22
0

You have a SQL error cause quotes. Try this request :

SELECT * FROM wisp_posts
CrazyMax
  • 781
  • 1
  • 11
  • 24
0

Firstly remove quotes from the query and try this:

$query = "SELECT * FROM wisp_posts";
$result = mysqli_query($con, $query);

while ($row = mysqli_fetch_array($result)) {
  echo $row[1];
}
user2936213
  • 1,041
  • 1
  • 8
  • 19
0

You don't need quotes under tables' names:

SELECT * FROM wisp_posts

Also, if you're new to PHP and MySQL you'd better study PDO object so you won't have to rewrite your code within a couple of months: PDO Tutorial

It's safer and faster, and easier to develop even for bigger projects.

Alan Piralla
  • 1,198
  • 2
  • 10
  • 21