Re: mysql_fetch_array()

From: Date: Fri, 18 Aug 2000 15:06:51 +0000
Subject: Re: mysql_fetch_array()
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-2160@lists.php.net to get a copy of this message
I think your goal was to loop over all columns in the result? correct? If you want to loop over the column indexes as you do, you need to do like this: $pocet = 0; while(isset($zanam[$pocet])) { echo $zaznam[$x]."\n"; echo "<br>*****<br>"; } Why?? Well, since mysql_fetch_array() returns a combined index and associative array. So if your table contains col1, col2, col3, col4, col5.... you will have these elements in the array from mysql_fetch_array() .. 0: value of first col in query col1: value of first col in query (but index is the name of the column instead of an index) 1: value of second col in query col2: ...... or.. array( 0 => "value", "col1" => "value", 1 => "value", "col2" => "value" ..... ); If you have problems with arrays in the future.. Do this to debug it..: while( list($key, $val) = each($array) ) { echo "$key: $val<br>"; } Just a tip.. I always do. Regards, Johan Andersson Consultant Qbranch System Management AB ----- Original Message ----- From: Sam Masiello <smasiello@chekinc.com> To: Libor Matyáš <matyasl@vscht.cz>; <php-db@lists.php.net> Sent: Friday, August 18, 2000 3:40 PM Subject: RE: [PHP-DB] mysql_fetch_array() > > If your goal with using a count was to obtain the number of rows returned > from your query, use this instead: > > $numrows = mysql_num_rows($proved) ; > > http://www.php.net/manual/function.mysql-fetch-array.php > http://www.php.net/manual/function.mysql-num-rows.php > > HTH > > Sam Masiello > System Analyst > Chek.Com > (716) 853-1362 x289 > smasiello@chekinc.com > > -----Original Message----- > From: Libor Matyáš [mailto:matyasl@vscht.cz] > Sent: Friday, August 18, 2000 9:27 AM > To: php-db@lists.php.net > Subject: [PHP-DB] mysql_fetch_array() > > Hello, > > this is the code i used: > $spojeni=mysql_connect("****","***","***"); > if (!spojeni) { > break; > } > mysql_select_db("***", $spojeni); > $proved=mysql_query("select * from tb_main",$spojeni); > while ($zaznam=mysql_fetch_array($proved)) { > $pocet=count($zaznam); > for($x=0; $x<$pocet; $x++) { > echo $zaznam[$x]."\n"; > echo "<br>*****<br>"; > } > echo $pocet; > } > > the table's got 5 fields, why does $pocet=10? > it's always double the number of fields the table has. > with ..fetch_row... one gets the right number. > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.db (#2160) next »