0

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.

2
  • 1
    Am I missing something, or do you not know how to work with arrays? Commented May 31, 2011 at 2:12
  • When I do '$books['bookID']' I only get one of the bookIDs that were in MySQL. I probably am forgetting something really basic... Commented May 31, 2011 at 2:13

2 Answers 2

5

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
}
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.