The problem is that you only apply mysql_fetch_row one time to the result.
The query 'select * from time where id>0' gives an array which can have
multiple rows.
For every row you have to apply mysql_fetch_row.

So you have to do something like this:

while ($row = mysql_fetch_row($result) {
  $id  = $row[0];
  $date = $row[1];
  $time = $row[2];

  echo "$id $date $time";  // you can put variables into the string when you
use double quotes!
  echo "<BR><BR>";
echo $total;

What also can be usefull is to use the function list. You then can do
something like:
while (list ($id, $date, $time) = mysql_fetch_row ($result) ....
and then skip the $id = $row[0] and so on.

If the time isn't in seconds you have to apply some functions to calculate
te total correctly


Coert Metz

ps. My excuses when my English doesn't fit all the rules ;)

// Connect to Database
$db = mysql_connect("localhost", "admin", "xxxxxxx");
$query = "select * from time where id > 0";
$result = mysql_query($query);
$row = mysql_fetch_row($result);

function totalsum()
  if($row[2] > 0)
    $totalsum1 = sum($row[2]);
    echo $totalsum;

if ($row[0] > 0)
  $id  = $row[0];
  $date = $row[1];
  $time = $row[2];

  echo $row[0] . " " . $row[1] . " " . $row[2];
  echo "<BR><BR>";
  echo "<B>Total:</B>";
  echo totalsum();


As I mentioned in a past mail, the purpose of this script, is to manage
values sent from a form, with the current date and the total amount of time
I spent on my Dial Up connection. Then it should display the last 30 days
connections (not implemented yet) and a total of the connection time (which
isn't working) for those days or current month.

Actually it displays only the first one of the records and doesn't display
the total. Can anybody help me out here? I know it's just a try, but it's
very important for my learning in order to see what I'm missing here.

Thanx in advance.

Cesar Aracena

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to