Re: Result is not empty

From: Date: Thu, 22 Nov 2001 23:02:43 +0000
Subject: Re: Result is not empty
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-14549@lists.php.net to get a copy of this message
Take out the while statement-- i.e. simply use: $row = mysql_fetch_array($result); the way you have things constructed now, the while statement evaluates true on the first iteration and $row equals the result row from the query. Because the while returned true, it is evaluated a second time, returns false, and $row = NULL. -ib
Why would that matter? He still sets the column variables on the first iteration? Yes, he needs no while loop, but the variables that are set inside the loop should remain set after the loop terminates.
Kevin Schaaps wrote:
Greetings once again, Today I hope to have a challenge for you. :) I've created a query which returns 1 record. This is confirmed when testing it in MySQL itself. Now PHP sees that there is 1 record in the result, but is completely unwilling to show the information. The css responsible for that page does not change the color of the text so it should (like all the rest of the page is) be visible. Please help :) Yours, Kevin ____________________________________________ $query = "SELECT concat(rank_tbl.abbreviation, ' ', character_tbl.name, ' ', character_tbl.surname) as CO,
              character_tbl.ircnick, character_tbl.email  FROM
character_tbl, rank_tbl, sim_tbl WHERE sim_tbl.co = character_tbl.id
              AND character_tbl.rank = rank_tbl.id AND sim_tbl.co =
character_tbl.id AND character_tbl.rank = rank_tbl.id
              AND sim_tbl.id = $sim_id";
    $result         =   mysql_query($query);
    $num_rows       =   mysql_num_rows($result);
    if ($num_rows == 1)
    {
        while ($row = mysql_fetch_array($result));
        {
            $co     =   $row["CO"];
            $nick   =   $row["ircnick"];
            $email  =   $row["email"];
        };
        echo "
            <table>
                <tr>
                    <td width=\"50\"></td>
                    <td width=\"125\">CO:<td>
                    <td><a href=\"$email\">$co</a></td>
                </tr>
                <tr>
                    <td width=\"50\"></td>
                    <td width=\"125\">IRC NICK<td>
                    <td>$nick</td>
                </tr>
                <tr>
                    <td width=\"50\"></td>
                    <td width=\"125\"><td>
                    <td></td>
                </tr>
            </table>";
    }
    else
    {
        echo "<br> <p class=\"medium\">No Commanding Officer assigned to
$name</p>";
    };


« previous php.db (#14549) next »