For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > March 2004 > Re: [PHP-DB] Display of fetched MySQL data?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-DB] Display of fetched MySQL data?
Ryszard Hapka

2004-03-26, 11:12 pm

Hi!
use foreach (www.php.net/foreach).

Ryszard

W. D. wrote:

>Hi Folks,
>
>I am trying to display a list of retrieved records, but can't seem
>to figure out how to do this properly. Here is what I am aiming
>for:
>
><?
>
>$result = mysql_query($SQLqry);
>
>$NumRows = mysql_num_rows($result);
>
>$NumFields = mysql_num_fields($result);
>
>// Loop through each row
>for ($RowIdx = 1; $RowIdx <= NumRows; $RowIdx++)
> {
> Echo "Record: ".($RowIdx + 1)."<BR>\n";
>
> // Loop through the fields
> for ($FieldIdx = 1; $FieldIdx <= NumFields; $FieldIdx++)
> {
> // Display the fields and associated data
>
> /* What code goes here????? */
>
> }
> } // End for ($RowIdx = 1; $RowIdx <= NumRows; $RowIdx++)
>
>?>
>
>How do I properly display the fieldname and its associated data?
>I know that you can do something like this using foreach, but
>I wanted a generic routine where you don't necessarily know
>the fieldnames.
>
>Any hints? (Thanks if you do!)
>
>Start Here to Find It Fast!™ -> http://www.US-Webmasters.com/best-start-page/
>
>
>



--
<?php
$me = array(
"name" => "Ryszard Hapka",
"mobile" => "693 340 403",
"GG_number" => "4765174",
"url_page" => "www.hary.rnet.pl"
);
?>
Ryszard Hapka

2004-03-26, 11:12 pm

not only foreach ;)

$r = mysql_query("select * from table");
while($t = mysql_fetch_assoc($r)) { // or while ($t =
mysql_fetch_array($r)) <-- you will see difrends
foreach($t as $key => $value) {
echo "[".$key."] ".$value ."<br />";
}
echo "<hr />";
}



Ryszard Hapka wrote:

> Hi!
> use foreach (www.php.net/foreach).
>
> Ryszard
>
> W. D. wrote:
>
>
>



--
<?php
$me = array(
"name" => "Ryszard Hapka",
"mobile" => "693 340 403",
"GG_number" => "4765174",
"url_page" => "www.hary.rnet.pl"
);
?>
W. D.

2004-03-26, 11:12 pm

Thanks! mysql_fetch_assoc did the trick.


At 07:08 3/25/2004, Ryszard Hapka wrote:
>not only foreach ;)
>
>$r =3D mysql_query("select * from table");
>while($t =3D mysql_fetch_assoc($r)) { // or while ($t =3D=20
>mysql_fetch_array($r)) <-- you will see difrends
> foreach($t as $key =3D> $value) {
> echo "[".$key."] ".$value ."<br />";
> }
> echo "<hr />";



Start Here to Find It Fast!=99 -> http://www.US-Webmasters.com/best-start-pa=
ge/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com