Monday, 6 February 2017

php - Select failing on hyphenated column name




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 '
  • '.$row["id"].'. '.$row["photo-url"].'
  • ';
    }
    echo '';



    Problem is:




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



    Answer



    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.


    No comments:

    Post a Comment

    c++ - Does curly brackets matter for empty constructor?

    Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...