more than one row..

Codes here !

Moderators: egami, macek, gesf

Post Reply
User avatar
New php-forum User
New php-forum User
Posts: 97
Joined: Mon Jul 07, 2003 10:30 pm
Location: Manchester

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.

"Don't look at the trombones - it only encourages them..."

User avatar
Posts: 2257
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

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" .
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.

Post Reply