Code Comments
Programming Forum and web based access to our favorite programming groups.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!(TM) ->
http://www.US-Webmasters.com/best-start-page/
Post Follow-up to this messageW. D. wrote: > 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!) > Check out the top example on this page: http://www.php.net/manual/en/functi...fetch-array.php And to get the field name itself: http://www.php.net/manual/en/functi...-field-name.php Albe -- http://www.ninja.up.ac.za
Post Follow-up to this messageW. 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!)
>
u also need to fetch the results. See the php mysql manual
part for more info.
Mart
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.