Re: var_dump() results

From: Date: Sun, 13 Jan 2008 18:47:58 +0000
Subject: Re: var_dump() results
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-267189@lists.php.net to get a copy of this message
Steve Edberg wrote:
As far as displaying only the first row, that's because you're only fetching the first row; count($row) in your for loop will always evaluate to 0 (if there are no results) or 1. You need to move the mysql_fetch_row() call into your loop; something like
    $result = mysql_query($sql);
    while ($row = mysql_fetch_row($result)) {
        var_dump($row);
        ...
    }
or you could do
    $result = mysql_query($sql);
    $count = mysql_num_rows($result);
    for ($i=0; $i<$count; $i++) {
        var_dump($row);
        ...
    }
Noted, thank you. I'll play with these too, to see what I think of them.
As far as displaying the results twice, I'm not sure; that resembles the behavior of mysql_fetch_array() -
The script had ~fetch_array() initially, I couldn't get it to work as expected so I changed it to ~fetch_row(). Now it's back to ~fetch_array() Both as a learning exercise and as an end-goal, I'm rewriting some code so that it does what I want it to, not what it imperfectly does according to the original programmers intent. That original intent bears only passing resemblance to what was requested of that programmer, it's become a sore subject.
    http://us.php.net/manual/en/function.mysql-fetch-array.php
- where the default is to return data as both an associative and numerically-indexed array.
That explains some things. And I have some reading and experimenting to do before I move on to the next step in the script.
I'm guessing that the above code isn't an exact cut-and-paste, as using single quotes (eg, mysql_pconnect('$host', '$login', '$passwd') does not interpolate variables, so that line will not work unless your username is actually '$login', etc. Which it probably isn't.
Correct. That was my attempt to obfuscate some of my real data, the username and password especially. See my other post on this. Ulex

« previous php.general (#267189) next »