[PHP-DB] Re: First Script

2002-05-20 Thread Coert Metz

I don't know how mysql_fetch_array() works. I think you have to handle this
by yourself
by putting something in the loop. You can also make a query for it (SELECT
sum(*) FROM time)

Coert

"César l . aracena" <[EMAIL PROTECTED]> schreef in bericht
002901c1feed$5695b2c0$94c405c8@gateway">news:002901c1feed$5695b2c0$94c405c8@gateway...
Thanx for the help. I have it almos finished. Now, the script throws all the
colums for all the rows of the table. My only problem now is how to print
the TOTAL for the column named time. Can I use mysql_fetch_array() instead
of mysql_fetch_row() to accomplish this? How can I add it?

Here's what I made so far:



 Connection Time



$column   ";
 }
 echo "";
}

// Insert new values into the table
if ($time <> "")
{
 $query = "insert into time " . "(date, time) values ('$date', '$time')";
 $result = mysql_query($query);
 $id = mysql_insert_id();
 $message = "Record Added (id = $id)";
}

if (isset($message))
{
 echo "$message";
}
?>

Clear the Form?








I added the "Clear the Form?" checkbox, so if I refresh using the PHP_SELF
won't insert the same data again. Is that ok?

Thanx and sorry for the trouble.

Cesar Aracena
[EMAIL PROTECTED]
Neuquen, Argentina




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




[PHP-DB] RE: First Script

2002-05-18 Thread César L . Aracena

Thanx for the help. I have it almos finished. Now, the script throws all the colums 
for all the rows of the table. My only problem now is how to print the TOTAL for the 
column named time. Can I use mysql_fetch_array() instead of mysql_fetch_row() to 
accomplish this? How can I add it?

Here's what I made so far:



 Connection Time



$column   ";
 }
 echo "";
}

// Insert new values into the table
if ($time <> "")
{
 $query = "insert into time " . "(date, time) values ('$date', '$time')";
 $result = mysql_query($query);
 $id = mysql_insert_id();
 $message = "Record Added (id = $id)";
}

if (isset($message))
{
 echo "$message";
}
?>

Clear the Form? 







I added the "Clear the Form?" checkbox, so if I refresh using the PHP_SELF won't 
insert the same data again. Is that ok?

Thanx and sorry for the trouble.

Cesar Aracena
[EMAIL PROTECTED]
Neuquen, Argentina



[PHP-DB] Re: First Script

2002-05-18 Thread Coert Metz

Hello

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:

$total=0;
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 "";
  $total+=$time
}
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

Success!!

Coert Metz

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


 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 "";
  echo "Total:";
  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