Jump to content

php whiles and loops


spinsfil

Recommended Posts

hi

 

i have a db of tv shows, episodes and descriptions. they are in the db like:

 

name    | series | episode | description

Friends  | 1      |  1          | example

Friends  | 1      |  2          | example

Scrubs    | 1      |  1          | example

 

I want to display it this way:

 

Friends

Series 1 Episode 1

Series 1 Episode 2

 

Scrubs

Series 1 Episode 1

 

cant seem to get it to fully work - it will display it for the first show but not do more than one

 

 

thanks for any help :)

Link to comment
Share on other sites

$getshows = mysql_query("SELECT * FROM showsdb GROUP BY series ASC, ep ASC ORDER BY id ASC") or die (mysql_error());

echo "<table>";

while ($row = mysql_fetch_array($getshows))
{
echo "<tr><td><b>$row[name]</b></td></tr>";



$row = mysql_fetch_array($getshows);
$count=1;
do {
if ($count>2) { $i="</tr><tr>"; $count=0;}
else { $i="";}
echo "<tr><td>Series $row[series] Episode $row[ep]</td></tr>";
echo $i;
$count++;
}


while ($row = mysql_fetch_array($getshows));
}

echo "</table>";

 

So far this code is doing it correctly for just the first show...

 

Link to comment
Share on other sites

Untested example (the query is changed, don't use group by):

 

$getshows = mysql_query("SELECT * FROM showsdb ORDER BY name ASC") or die (mysql_error());
$name = '';

echo "<table>";

while($row = mysql_fetch_array($getshows)) {
    if($row['name'] != $name) {
        echo "<tr><td><b>".$row['name']."</b></td></tr>";
        $name = $row['name'];
    }
    echo "<tr><td>Series ".$row['series']." Episode ".$row['ep']."</td></tr>";
}
echo "</table>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.