1

I want to select two fields from the database, id an photo-url.

Code is:

$results = mysqli_query($connecDB,"SELECT id, photo-url FROM list ORDER BY id ASC LIMIT ".$position.", ".$item_per_page."");

while($row = mysqli_fetch_array($results)){
    echo '<li id="item_'.$row["id"].'">'.$row["id"].'. <span class="page_name">'.$row["photo-url"].'</li>';
}
echo '</ul>';

Problem is:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in...(line while).

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Gab
  • 69
  • 8

2 Answers2

7

photo-url wrap that column name in ticks. SQL is interpreting that as "photo MINUS url".

SELECT id, `photo-url`

or rename it using an underscore

SELECT id, photo_url

that way you won't have to use ticks.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
1
$results = mysqli_query($connecDB, "SELECT `id`, `photo-url` FROM `list` ORDER BY `id` ASC LIMIT ".$position.", ".$item_per_page."");

Use the ` symbol in queries to quote the names of fields or tables.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
David Demetradze
  • 1,361
  • 2
  • 12
  • 18