PHP: table structure

Posted by A3efan on Stack Overflow See other posts from Stack Overflow or by A3efan
Published on 2010-12-27T17:38:19Z Indexed on 2010/12/28 17:54 UTC
Read the original article Hit count: 309

Filed under:
|
|
|
|

I'm developing a website that has some audio courses, each course can have multiple lessons. I want to display each course in its own table with its different lessons.

This is my sql statement:

Table: courses

id, title

Table: lessons

id, cid (course id), title, date, file

        $sql = "SELECT lessons.*, courses.title AS course FROM lessons INNER JOIN courses ON courses.id = lessons.cid GROUP BY lessons.id ORDER BY lessons.id" ;

Can someone help me with the PHP code?

This is the I code I have written:

mysql_select_db($database_config, $config);
    mysql_query("set names utf8");
    $sql = "SELECT lessons.*, courses.title AS course FROM lessons INNER JOIN courses ON courses.id = lessons.cid GROUP BY lessons.id ORDER BY lessons.id" ;
    $result = mysql_query($sql) or die(mysql_error());
    while ($row = mysql_fetch_assoc($result)) {
        echo "<p><span class='heading1'>" . $row['course'] . "</span> </p> ";               
        echo "<p class='datum'>Posted onder <a href='*'>*</a>,  latest update on " . strftime("%A %d %B %Y %H:%M", strtotime($row['date']));
        }
        echo "</p>";
        echo "<class id='text'>";
        echo "<p>...</p>";
        echo "<table  border: none cellpadding='1' cellspacing='1'>";
        echo      "<tr>";
        echo        "<th>Nr.</th>";
        echo        "<th width='450'>Lesso</th>";
        echo        "<th>Date</th>";
        echo        "<th>Download</th>";
        echo      "</tr>";
        echo      "<tr>";
        echo        "<td>" . $row['nr'] . "</td>";
        echo        "<td>" . $row['title'] . "</td>";
        echo        "<td>" . strftime("%d/%m/%Y", strtotime($row['date'])) . "</td>";
        echo        "<td><a href='audio/" . rawurlencode($row['file']) . "'>MP3</a></td>";
        echo      "</tr>";
        echo    "</table>";                 
        echo "<br>";
    }
    ?>

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql