Jump to content


Photo

Multiple Ranking Tables in one query


  • Please log in to reply
1 reply to this topic

#1 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 24 May 2006 - 02:46 PM

Hi i have a table called members and the following fields

firstname
middlename
lastname
age

what i want is a table with the ages and then the number of people in members in that age with the same names as me....

i.e.


age - firstname - middlename - lastname
18 - 6 - 4 - 1
21 - 12 - 6 - 15

and so on....

any ideas please...?

#2 markduce

markduce
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 24 May 2006 - 03:04 PM

$firstname="Mark";
$middlename="David";
$lastname="Duce";
$times=100;
$x=1;

echo "<table><tr><th>Age</th><th>First Name</th><th>Surname</th></tr>";
while ($x<$times) {

$countfirst=mysql_num_rows(mysql_query("SELECT * FROM members WHERE firstname='$firstname'"));
$countmiddle=mysql_num_rows(mysql_query("SELECT * FROM members WHERE middlename='$middlename'"));
$countsecond=mysql_num_rows(mysql_query("SELECT * FROM members WHERE lastname='$lastname'"));

echo "<tr><td>".$x."</td><td>";
echo "".$countfirst."</td><td>".$countmiddle."</td><td>".$countsecond."</td></tr>";


$x++;

}
echo "</table>";




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users