[Solved]Listing things using PHP and MySQL?

Discussion about the creation of websites in general, HTML, PHP, Java.

[Solved]Listing things using PHP and MySQL?

Postby JaMaHa on Fri Sep 22, 2006 4:48 pm

Okay, so what I'm trying to do is to list some stuff from a MySQL database. The table has values "Game" and "Name"

What I want to do is to get the script list all the names under the corresponding game. Eg:

The values listed in the database:

Metroid - Ending
Super Mario Bros. - Overworld
Metroid - Brinstar
Super Mario Bros. - Underwater
Metroid - Norfair

( Where the word before - is the value of Game and the word after - is the value of Name )

I would want them to be listed like this:

Metroid
Ending
Brinstar
Norfair

Super Mario Bros.
Overworld
Underwater

Is there a way to do that?
Last edited by JaMaHa on Sat Sep 23, 2006 6:45 pm, edited 1 time in total.
Image
JaMaHa
Regular
Regular
 
Posts: 93
Joined: Mon May 08, 2006 3:54 pm
Location: Finland

Postby Willyham on Sat Sep 23, 2006 10:51 am

Seeing as the 'Name' field is being organized in a non alphabetical order, you will need a third field, like 'ID' to add the names with. Then you can do:

Code: Select all
<?
function list($game) {
   $sql = "SELECT * from `yourtable` WHERE `game` = '$game' ORDER BY `id` ASC";
   $result = mysql_query($sql);
   $row = mysql_fetch_array($result);
   echo "<b>$game</b>";
   for ($i = 0; $i < count($game); $i++) {
      echo "$row['name']";
   }
}
?>


Something like that... but dont hold me to it. Laughing
Image
Willyham
Contributer
Contributer
 
Posts: 32
Joined: Sun Aug 27, 2006 3:51 pm
Location: Nottingham, England.

Postby JaMaHa on Sat Sep 23, 2006 6:44 pm

Got it working with some help from a friend, thanks anyway.
Image
JaMaHa
Regular
Regular
 
Posts: 93
Joined: Mon May 08, 2006 3:54 pm
Location: Finland


Return to General Webmastering

Who is online

Users browsing this forum: No registered users and 1 guest

cron