开发者

I can't get multiple values out of MySQL using a select statement in PHP

This is my code:

$bookresult = mysqli_开发者_如何学编程query($db, "SELECT bookID 
                                   FROM order_items 
                                  WHERE orderID = '".$orders['orderID']."';");

The problem I have is that there are multiple bookIDs that are pulled out of MySQL. So when I do this:

$books = mysqli_fetch_array($bookresult);

There is no way for me to get all the bookIDs that should show when using that select statement, unless I'm doing something wrong.


mysqli_fetch_array($bookresult) must be run multiple times until it returns null. Just do a loop like so:

while ($book_result_row = mysqli_fetch_array($bookresult)) {
    // Do something with your $book_result_row
}


You need to use a loop to go through all of the values.

You can view them by using the following php code. (You can use mysql_fetch_array in place of mysql_fetch_assoc if you wish.

while ($books_row = mysql_fetch_assoc($bookresult)) {
  //output here.
  echo "<pre>";
  print_r($books_row);
  echo "</pre>";
}

The output there is great for debugging...replace it with what you think is best after you solve this problem. :) Hope this helped.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜