Re: var_dump() results

From: Date: Mon, 14 Jan 2008 17:25:38 +0000
Subject: Re: var_dump() results
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-267223@lists.php.net to get a copy of this message
On Sun, January 13, 2008 11:32 am, 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. > > Here's my code: > > <?php > > //connect to db > $link = mysql_pconnect('$host', '$login', '$passwd'); '$host' is not right. $host is right. Ditto for ALL your values throughout this script. > if (!$link) { > die('Unable to connect : ' . mysql_error()); Forget the loop, this should have puked right here, or you aren't posting your actual code... > } > // 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++){ The $row only has TWO columns in it: column2, column3 The $result may have many, many, many rows in it. You can find out HOW many by using: http://php.net/mysql_num_rows -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So?

« previous php.general (#267223) next »