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
more than one row..
Moderators: egami, macek, gesf
- frogrocker
- New php-forum User
- Posts: 97
- Joined: Mon Jul 07, 2003 10:30 pm
- Location: Manchester
- swirlee
- Moderator
- Posts: 2257
- Joined: Sat Jul 05, 2003 1:18 pm
- Location: A bunk in the back
- Contact:
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:
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.
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.