Re: var_dump() results

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Europus wrote:
It's pretty much the same. With var_dump(), values from the first row
of the table are iterated twice, the script is not looping through and
reporting all 2100 rows. Grossly similar behavior was observed with
print_r() and echo: while different data was reported by each, the
loop wouldn't loop. The first row was reported once (or twice) and
that was the end of that. I've tried foreach() also, same-same. It
doesn't loop, it just reports the first row.

It doesn't loop through all rows because you use mysql_fetch_row. Wich does exactly what it's name tells you. It fetches one single row. So instead of looping through the whole result set. You are looping through every cell off the result set. You're probably
better of using mysql_fetch_array().

Here's my code:

<?php

//connect to db
$link = mysql_pconnect('$host', '$login', '$passwd');
if (!$link) {
    die('Unable to connect : ' . mysql_error());
}
// make $table the current db
$db_selected = mysql_select_db('$table', $link);
if (!$db_selected) {
    die ('Unable to select $table : ' . mysql_error());
}

//get column data
    $sql    = "SELECT column2, column3 FROM $table";
    $result = mysql_query($sql);
    $row = mysql_fetch_row($result);

//loop through to display results
for($i=0; $i < count($row); $i++){
    var_dump($row);
    echo "<br /><br />";
?>

Ulex


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux