Hello all... I'm trying to make a bar graph, but I'm running into problems... The problem is that for every age in the array, I only want to display ONE row. But the way this is set up, it displays every instance of the $row[age]... I know why it's doing that, but I don't know of any other way to either combine the $row[age] results, or set up an if else statement so that each $row only get's echoed once.... So, yeah... That's where I'm at.
Any help here would be great. Thank you! 🙂
Here's the code I've got so far:
<?
include('../dbinfo.inc.php');
$db = mysql_pconnect("localhost", $username, $password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contest ORDER BY age";
$result=mysql_query($query);
$num=mysql_numrows($result);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<link href="../../linksnew.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="650" border="0" align="center" cellpadding="1" cellspacing="0" bgcolor="#999999">
<tr>
<td><table width="650" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#333333">
<tr>
<td width="39"><div align="center">Age</div></td>
<td width="562"><div align="center">Percentage</div></td>
<td width="49"><div align="center">Total Entries </div></td>
</tr>
<?
$i=0;
$tdcount=0;
while($row = mysql_fetch_array($result)) {
$query2 = "select * from contest where age = '$row[age]'";
$res2 = mysql_query($query2,$db)or die("broken on query2");
$num_age = mysql_num_rows($res2);
$age=mysql_result($result,$i,"age");
if($cellcolor=='454545')
{
$cellcolor='545454';
}
else
{
$cellcolor='454545';
}
?>
<?
if($num_age>=1){?>
<tr bgcolor="<? echo $cellcolor;?>" height="20">
<td height="25"><div align="center">
<?
echo $age;
//Eventually this will be the total number in the array divided by the total number of entries multiplied by 100 to get a width percentage...
//For now it's random just to have something to display...
$random=rand(0,100);
?>
</div></td>
<td height="25"><table width="<? echo $random; ?>%" border="0" cellpadding="0" cellspacing="0" bgcolor="#999999">
<tr>
<td><center><span class="whitetiny"><? echo $random ."%";?></span></center></td>
</tr>
</table></td>
<td height="25"><center><? echo $num_age; ?></center></td>
</tr>
<?
++$i;
}
}?>
</table></td>
</tr>
</table>
</body>
</html>