1

the following mysql query is only returning a single row when it should be returning 4.

$query = "SELECT * FROM questions";
    $result = mysql_query($query) or die("ERROR: $query.".mysql_error());
    // if records are present
    if (mysql_num_rows($result) > 0) {
    while ( $row = mysql_fetch_object($result) ){

    // get question ID and title
        $qid = $row->qid;
        echo '<div id=ques>';
        echo '<h2>'.$row->qtitle .'</h2>';
        echo '</div>';

        print_r ($row);

the print_r function displays this:

stdClass Object ( [qtitle] => dummy text here [qid] => 1 )
1
  • 1
    You should be very careful with the way you generate your HTML. If the question titles come from user input you may have an XSS or DoS vulnerability in your code. Commented Jan 19, 2010 at 22:09

2 Answers 2

4

mysql_fetch_*() only pulls a single row at a time. Without seeing the rest of the loop it's impossible to tell if something else is going on down there.

Sign up to request clarification or add additional context in comments.

3 Comments

@Ignacio, doesn't the while loop keep calling mysql_fetch_object until it returns FALSE? I agree the block could contain other code that may break out of the loop.
Also looks like it's missing some crucial closing brackets which could possibly be causing it to break, would expect parse errors with that code though ..
this was a really stupid question. it was an error on my part. i took the $row variable for fetching the answers too. thanks for your help.
0

You don't have closing brackets for while-loop and if

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.