More than 2 while loops (repeating regions)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cookie_monster
Forum Newbie
Posts: 5
Joined: Sat Apr 12, 2003 8:41 am
Location: Australia

More than 2 while loops (repeating regions)

Post 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 :?: :?: :?:
ckuipers
Forum Commoner
Posts: 61
Joined: Mon Mar 24, 2003 6:10 am

Post 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.
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post 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 ;))
Post Reply