Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

more than one row..

Codes here !

Moderators: macek, egami, gesf

more than one row..

Postby frogrocker » Mon Jul 14, 2003 8:42 am

I'm using a mysql_query() statement like this...

$results = mysql_query("SELECT * FROM Calendar WHERE date = $datestring");

this will sometimes return more than one row. Is it possible to put the columns returned in a table, and how.

Do I use mysql_fetch_array()?

I have tried this, but it only returns the first row.

TIA
User avatar
frogrocker
New php-forum User
New php-forum User
 
Posts: 98
Joined: Mon Jul 07, 2003 10:30 pm
Location: Manchester

Postby swirlee » Mon Jul 14, 2003 10:31 am

mysql_fetch_array() will return a new row each time you call it. Once you've reached the last row of the result set, it'll return false. The usual method to retrieving all of the rows of a result set is in a while loop. To put the output into a table, just to echo the appropriate HTML with every row. For example:


Code: Select all
echo "<table>\n";
while ($row = mysql_fetch_array($result)) {
   echo  "\t<tr>\n" .
         "\t\t<td>" . $row['id'] . "</td>\n" .
         "\t\t<td>" . $row['name'] . "</td>\n" .
         "\t\t<td>" . $row['location'] . "</td>\n" .
         "\t</tr>\n";
}
echo "</table>\n";


By the way, the \t and \n are for formatting only. I like my HTML to come out clean. As is usual, the documentation is your best friend.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back


Return to mySQL & php coding

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.