dinno2 wrote:what i am trying to acomplish is, to get a pilots total number of hours from mysql . The pilot simply enters each flight using a form that sends the information to mysql, the hours are listed under hours, simple enough. The querry i used in here works with mysql admin, but im doing something wrong here with the php end, i have been reading both php and mysql manuals, and have tried several differnt ways to go about this, with the same results, failure. ideas, or documentation sure would be appreciated.
heres the code i have, im new so dont laugh <G>
Code: Select all
<?php
mysql_connect (xxxx, xxxx, xxxx);
mysql_select_db (xxxx);
if ($pilotid == "")
{$pilotid = '%';}
$result = mysql_query ("SELECT * SUM(hours) AS Total FROM pirep where pilotid LIKE '$pilotid%'");
if ($row = mysql_fetch_array($result)) {
do {
print "<td>{$rowї'hours']}</TD>\n";
?>
nielsene is correct it should be $row['Total'].
but in your select you can't have SELECT
* SUM(hours)...
it has to be SELECT SUM(hours) as Total from...
If you wanted to use * then you would need to GROUP BY on all of the columns, but this rather defeats the purpose of SUM as each record would be unique giving you back each individual record rather than a SUM of group records.
You say that one of the errors is 'Wrong parameter count for mysql_db_query...', but in the code you posted nowhere was a call to mysql_db_query. But as Takuma said you should use mysql_query().
And it is okay to use single quotes (') around the field name, makes it easier if your string is enclosed in double quotes (")
print "<td>$row['Total']</td>";