...

View Full Version : coding error



Dan13071992
12-05-2010, 12:04 AM
hello everyone, i have had alot of trouble tring to get this script to work, it is only a partial as the rest of the page does work, but what happens is, where the outputs are on the page as statistics it only shows up as a 0 this is due to the [0] that is next to some of the statistics from the php code itself however i have tried many attempts, so any help would be great.


/////////ranks///////////

/////////godfather/////////

$godfather = mysql_query("SELECT rank FROM users WHERE rank = 'Godfather'");
$totalgodfather = 0;
while($rowgodfather=mysql_fetch_array($godfather)){
$totalgodfather+=$rowgodfather[0];
}


$godfatheralive = mysql_query("SELECT rank FROM users WHERE rank = 'Godfather' AND status = 'Alive'");
$totalgodfatheralive = 0;
while($rowgodfatheralive=mysql_fetch_array($godfatheralive)){
$totalgodfatheralive+=$rowgodfatheralive[0];
}

$godfatherpercentalive = round($totalgodfatheralive / $godfather);

/////////druglord///////////

$druglord = mysql_query("SELECT rank FROM users WHERE rank = 'Druglord'");
$totaldruglord = 0;
while($rowdruglord=mysql_fetch_array($druglord)){
$totaldruglord+=$rowdruglord[0];
}


$druglordalive = mysql_query("SELECT rank FROM users WHERE rank = 'Druglord' AND status = 'Alive'");
$totaldruglordalive = 0;
while($rowdruglordalive=mysql_fetch_array($druglordalive)){
$totaldruglordalive+=$rowdruglordalive[0];
}

$druglordpercentalive = round($totaldruglordalive / $druglord);


//////////Underboss/////////

$underboss = mysql_query("SELECT rank FROM users WHERE rank = 'Underboss'");
$totalunderboss = 0;
while($rowunderboss=mysql_fetch_array($underboss)){
$totalunderboss+=$rowunderboss[0];
}


$underbossalive = mysql_query("SELECT rank FROM users WHERE rank = 'Underboss' AND status = 'Alive'");
$totalunderbossalive = 0;
while($rowunderbossalive=mysql_fetch_array($underbossalive)){
$totalunderbossalive+=$rowunderbossalive[0];
}

$underbosspercentalive = round($totalunderbossalive / $underboss);

/////////////Consigliere///////

$consigliere = mysql_query("SELECT rank FROM users WHERE rank = 'Consigliere'");
$totalconsigliere = 0;
while($rowconsigliere=mysql_fetch_array($consigliere)){
$totalconsigliere+=$rowconsigliere[0];
}


$consiglierealive = mysql_query("SELECT rank FROM users WHERE rank = 'Consigliere' AND status = 'Alive'");
$totalconsiglierealive = 0;
while($rowconsiglierealive=mysql_fetch_array($consiglierealive)){
$totalconsiglierealive+=$rowconsiglierealive[0];
}

$consiglierepercentalive = round($totalconsiglierealive / $consigliere);

///////////Capo////////////


$capo = mysql_query("SELECT rank FROM users WHERE rank = 'Capo'");
$totalcapo = 0;
while($rowcapo=mysql_fetch_array($capo)){
$totalcapo+=$rowcapo[0];
}


$capoalive = mysql_query("SELECT rank FROM users WHERE rank = 'Capo' AND status = 'Alive'");
$totalcapoalive = 0;
while($rowcapoalive=mysql_fetch_array($capoalive)){
$totalcapoalive+=$rowcapoalive[0];
}

$capopercentalive = round($totalcapoalive / $capo);

/////////end////////////




thank you in advance if you can help me out.

Lamped
12-05-2010, 12:35 AM
What's in the rank field?

Dan13071992
12-05-2010, 12:37 AM
`rank` enum('Tramp','Paper Kid','Theif','Robber','Gangster','Associate','Piciotto','Made Man','Capo','Consigliere','Underboss','Druglord','Godfather','HDO','Head HDO','Mod','Head Mod','Administrator') NOT NULL default 'Tramp',

thats whats in the database.


<tr>
<td>Godfather</td>
<td><?php echo "".makecomma($totalgodfatheralive).""; ?></td>
<td><?php echo "".makecomma($godfatherpercentalive)."%"; ?></td>
<td><?php echo "".makecomma($totalgodfather).""; ?></td>
</tr>


thats where it should be displayed, however where it should be displayed they all come up as 0

Lamped
12-05-2010, 12:59 AM
Then, if I understand correctly, you want to "SELECT COUNT(*) ..."



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum