MySQL Forums
Forum List  »  Newbie

Re: Display sum of table in one line of text?
Posted by: Matthew Jones
Date: March 29, 2005 07:58AM

I have been having a play with some different tutorials, and managed to come up with this: www.tangoforce.com/test.php.

It uses the query you gave me, but there are two slight problems. The first is that it displays the ENTIRE score, including all decimal places - I need it to be to just 2 decimal places.

The other is that its ordering them by only the first number (so 3 is the same as 30, or 300, rather than 30 being higher than 3).

Using the echos seems much simpler, and easier to format how you want it on the page. :D

Here is the script:
-----------------------------------------------------------------------------
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");


$query="SELECT name, nat, kills, deaths,
IF (deaths, kills / deaths, 'flawless') AS score
FROM `tfcoop`
ORDER BY score DESC";

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

?>

<b><center>Databse Output</center></b><br><br>

<?

$i=0;
while ($i < $num) {

$name=mysql_result($result,$i,"name");
$nat=mysql_result($result,$i,"nat");
$kills=mysql_result($result,$i,"kills");
$deaths=mysql_result($result,$i,"deaths");
$score=mysql_result($result,$i,"score");

echo "<b>Name: $name</b><br>Nat.: $nat<br>Kills: $kills<br>Deaths: $deaths<br>Score: $score<br><hr><br>";

$i++;
}

?>

</html>
-----------------------------------------------------------------------------

Now how would I make it display the total kills, deaths and kills/deaths as a total somewhere on the page?

Also, how would I make a form that adds the data entered to existing data? (So the number I enter in a field is added to the exisitng amount in the kills field, for example)

Options: ReplyQuote


Subject
Written By
Posted
Re: Display sum of table in one line of text?
March 29, 2005 07:58AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.