tags:

views:

69

answers:

2

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 )
+4  A: 

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.

Ignacio Vazquez-Abrams
@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.
AJ
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 ..
foxed
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.
amit
@AJ: C​orrect​.
Ignacio Vazquez-Abrams
A: 

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

alemjerus