Page 1 of 1

More than 2 while loops (repeating regions)

Posted: Sat Apr 12, 2003 8:41 am
by cookie_monster
I am fairly new to PHP so here is my problem.
I have this database which has 2 tables. I want to retrieve everything out of one column in each table.
I have set everything up and the first while loop works fine but the last while loop does nothing, not even a error message.
Here is the code:

<?php
$facilities_result=mysql_query("SELECT * FROM tbl_facilities WHERE id='$club'");
$todays_result=mysql_query("SELECT * FROM tbl_activities WHERE id='$club'");
?>




<?php

while($facilities_row=mysql_fetch_array($facilities_result))
{
echo(" ".$facilities_row["name"]);
}
?>

<br>
<br>
<b>Todays Activities</b><br>
<?php
while($todays_row=mysql_fetch_row($todays_result))
{
echo($todays_row["name"]."</br>");
}
?>


Thanks in advanced,
Joe :?: :?: :?:

Posted: Sat Apr 12, 2003 8:52 am
by ckuipers
I don't see an immediate problem with the code. However, are you sure the column in the table is called with 'name'? If you column has a different name it won't work.

Posted: Sat Apr 12, 2003 9:21 am
by Jim
I think I see the problem. You left the other ." out.

To make it simpler, why not do it like this?

Code: Select all

while($facilities_row = mysql_fetch_array($facilities_result)) {
        $facilities_name = $facilities_row['name'];

        echo $facilities_name;
        }
I guess it's all a matter of personal preference, but I think that is more readily understandable and cleaner looking (at least when I code it in notepad ;))