For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > January 2006 > Display Multiple Rows in PHP and MYSQL









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 Display Multiple Rows in PHP and MYSQL
ameshkin

2006-01-10, 4:00 am

I know this is probably not too hard to do, but how do I display
multiple rows of a mysql query/recordset. Im having trouble doing
this. I don't just want to display them, but I want to make sure ONE
field in each row gets a variable.

The table name is RecentUploads, the field I want to pull is XML

This is probably something simple that is more experienced, but I've
only been doing this for a couple of months. Any help would be
appreicated.

Thank You

http://www.mytuneslive.com

Snappy

2006-01-10, 4:00 am

Try this:

$query = "SELECT * FROM TABLENAME"; //or whatever SQL you want to use
$recset = mysql_query($query,$db_conn) or die("Error message if query
fails");
if( mysql_num_rows($recset) < 1 )
{
// no records found for query
}
else
{
while( $row = mysql_fetch_assoc($recset) )
{
//put output code here
}
}

If you are using a table to display the records make sure to put the
table tag and its heading row before the while statement and put the
closing table tag after the while block. Inside the while loop you
would code the output for an entire table row.

More help available at http://www.php.net/manual/en/ref.mysql.php look
up MySQL functions under Functions Reference on sidebar.

Jim Michaels

2006-01-16, 3:55 am

if you don't need the "no records found", you can remove it like this:

$recset = mysql_query("SELECT * FROM TABLENAME",$db_conn) or die("Error
message if query
fails");
while($row = mysql_fetch_array($recset)) {
//put output code with $row['XML'] here
echo $row['XML'];
echo "here is some $row[XML]\n";
}

(I am used to using mysql_fetch_array - the other function does the same
thing anyway - your choice)

"Snappy" <freethot@libertyhaven.com> wrote in message
news:1136868122.600214.165390@g14g2000cwa.googlegroups.com...
> Try this:
>
> $query = "SELECT * FROM TABLENAME"; //or whatever SQL you want to use
> $recset = mysql_query($query,$db_conn) or die("Error message if query
> fails");
> if( mysql_num_rows($recset) < 1 )
> {
> // no records found for query
> }
> else
> {
> while( $row = mysql_fetch_assoc($recset) )
> {
> //put output code here
> }
> }
>
> If you are using a table to display the records make sure to put the
> table tag and its heading row before the while statement and put the
> closing table tag after the while block. Inside the while loop you
> would code the output for an entire table row.
>
> More help available at http://www.php.net/manual/en/ref.mysql.php look
> up MySQL functions under Functions Reference on sidebar.
>



Sponsored Links







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

Copyright 2009 codecomments.com