Jump to content

[SOLVED] Needs help Urgent Please!


studgate

Recommended Posts

If they are on the same page I would use a form with radio buttons for the user to select the report required rather than links.

 

<html>
<head>
<meta name="generator" content="PhpED Version 4.5 (Build 4513)">
<title>Sample reports code</title>
<meta name="author" content="Barand">

</head>
<body>
<form method="get">
<h3>Choose report type </h3>
<input type="radio" name="name" value="Artist"> by Artist<br>
<input type="radio" name="name" value="Genre"> by Genre<br>
<input type="radio" name="name" value="Year"> by Year<br>
<input type="radio" name="name" value="Type"> by Type<br> <br>
<input type="submit" name="action" value="Show report">
</form>
<?php
include 'db.php'; // database connection code

if (isset ($_GET['name']))   {
        switch ($_GET['name']) {
            case 'Artist' :
                $sql = "SELECT a.artist, COUNT(*) as num
                        FROM music m INNER JOIN artist a
                        ON m.artist_id = a.id
                        GROUP BY a.artist
                        ORDER BY num DESC";
                break;
                
            case 'Genre' :
                $sql = "SELECT g.genre, COUNT(*) as num
                        FROM music m INNER JOIN genre g
                        ON m.genre_id = g.id
                        GROUP BY g.genre
                        ORDER BY num DESC";
                break;
                
            case 'Type' :
                $sql = "SELECT t.type, COUNT(*) as num
                        FROM music m INNER JOIN musictype t
                        ON m.type_id = t.id
                        GROUP BY t.type
                        ORDER BY num DESC";
                break;
                
            case 'Year' :
                $sql = "SELECT m.year, COUNT(*) as num
                        FROM music m 
                        GROUP BY m.year
                        ORDER BY num DESC";
                break;
        }

        $res = mysql_query ($sql);
        echo '<table border="1" cellpadding="4">';
        while (list($descrip, $num) = mysql_fetch_row($res)) {
             echo "<tr><td>$descrip</td><td>$num</td></tr>";
        }
        echo '</table>';
}
?>
</body>
</html>

Link to comment
Share on other sites

 

CREATE TABLE music (
    id int not null auto_increment primary key,
    song_title varchar(100),
    artist_id int,
    genre_id int,
    year int,
    type_id int
)

Hi Barand, artist, genre, & type cannot be integers, I just realized that.

& also my form add the data to the music database & then insert the

artist, genre, year, & type in their respectives database, should I consider

re-writing the form.

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.