Barand Posted February 23, 2007 Share Posted February 23, 2007 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> Quote Link to comment Share on other sites More sharing options...
studgate Posted February 23, 2007 Author Share Posted February 23, 2007 Thanks Barand, for all the help, I am going to put everything together again to see if it works. Quote Link to comment Share on other sites More sharing options...
studgate Posted February 23, 2007 Author Share Posted February 23, 2007 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. Quote Link to comment Share on other sites More sharing options...
studgate Posted February 23, 2007 Author Share Posted February 23, 2007 Forget about my last comment about the integers can you give me an example for the artist mysql query. Thanks again! Quote Link to comment Share on other sites More sharing options...
Barand Posted February 23, 2007 Share Posted February 23, 2007 Read my reply #25 above - it has all 4 report queries Quote Link to comment Share on other sites More sharing options...
studgate Posted February 23, 2007 Author Share Posted February 23, 2007 I meant the query to create the tables (artist, genre, etc) into the databases. One simple example will do. Thanks! Quote Link to comment Share on other sites More sharing options...
Barand Posted February 23, 2007 Share Posted February 23, 2007 As you had before without the `nr` bigint column. Quote Link to comment Share on other sites More sharing options...
studgate Posted February 23, 2007 Author Share Posted February 23, 2007 Thanks Barand, I consider this topic solved. I have everything working the way it is supposed to. Thanks again everybody who helps, specially Barand. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.