Help with COUNT() on a php form
Help with COUNT() on a php form
am 10.01.2006 16:23:59 von bigsamurai
Good day... I have included the code of a form that i am trying to get
to work. The object of the form will be to show a person the number of
flight hours they have and the number of flights that they have
accomplished. However I am getting an error saying that the result can
not be found. PLZ HELP as I am pullingm y hair out and do not have
much left to begin with.!!!
$query = "SELECT mission.miss_pilot_assign,
pilot.pilot_no, pilot.pilot_name,
mission.miss_status,
mission.miss_no,
mission.miss_hours
FROM mission, pilot
WHERE
mission.miss_pilot_assign=pilot.pilot_no
AND
mission.miss_status=3
AND
pilot.pilot_name='$_POST[pilot_name]'
GROUP
by mission.miss_status";
$result=@mysql_query($query);
$number = mysql_numrows($result);
if ($number > 0) {
print "
Here are the flight statistics for '$_POST[pilot_name]'as
recorded by Squadron Operations.
";
print "";
print "";
print "
face=Arial color=#FFFFFF size=2>Number of missions | ";
print "
face=Arial color=#FFFFFF size=2>Number of Hours | ";
print "
";
/* Get pilots info */
for ($i=0; $i<$number; $i++) {
$miss_tot = mysql_result($result,$i,"(COUNT(miss_no))");
$hours_tot =
mysql_result($result,$i,"(SUM(miss_hours))");
/* Display roster entries */
print "";
print "
face=Arial size=2 color=#FFFFFF>$miss_tot | ";
print "
face=Arial size=2 color=#FFFFFF>$hours_tot | ";
print "
";
}
print "
";
}
/* Close the database connection */
mysql_close();
?>
Re: Help with COUNT() on a php form
am 10.01.2006 16:46:22 von Shion
bigsamurai wrote:
> Good day... I have included the code of a form that i am trying to get
> to work. The object of the form will be to show a person the number of
> flight hours they have and the number of flights that they have
> accomplished. However I am getting an error saying that the result can
> not be found. PLZ HELP as I am pullingm y hair out and do not have
> much left to begin with.!!!
> /* Get pilots info */
> for ($i=0; $i<$number; $i++) {
> $miss_tot = mysql_result($result,$i,"(COUNT(miss_no))");
> $hours_tot =
> mysql_result($result,$i,"(SUM(miss_hours))");
I think you have misunderstood how mysql_result() works, it's used to get a
column from your result from the mysql_query().
You have the following columns that you can use:
mission.miss_pilot_assign,
pilot.pilot_no, pilot.pilot_name,
mission.miss_status,
mission.miss_no,
mission.miss_hours
$miss_tot = mysql_result($result,$i,"mission.miss_no");
$hours_tot = mysql_result($result,$i,"mission.miss_hours");
Of course this will not be the total amount of hours per pilot or how many
missions they have done, it's just the result from that line in the joined table.
You would need to make an additional query to get those two:
$query = "SELECT COUNT(mission.miss_no),
SUM(mission.miss_hours)
FROM mission, pilot
WHERE
mission.miss_pilot_assign=pilot.pilot_no
AND
mission.miss_status=3
AND
pilot.pilot_name='$_POST[pilot_name]'
GROUP
by mission.miss_status";
//Aho
Re: Help with COUNT() on a php form
am 10.01.2006 17:00:07 von bigsamurai
So then my second query would be like "$query1"? and then add a
"$result1" as well?
Re: Help with COUNT() on a php form
am 10.01.2006 17:06:48 von Shion
bigsamurai wrote:
> So then my second query would be like "$query1"? and then add a
> "$result1" as well?
It's all up to you, if you have finished everything you wanted to use the
first query for, then you could reuse the variables.
//Aho
Re: Help with COUNT() on a php form
am 10.01.2006 18:02:20 von bigsamurai
now i get this error...
Warning: mysql_result(): supplied argument is not a valid MySQL result
resource in /home/content/m/i/k/mikey05156/html/ind_pilotins.php on
line 48
Warning: mysql_result(): supplied argument is not a valid MySQL result
resource in /home/content/m/i/k/mikey05156/html/ind_pilotins.php on
line 49
line 48 and 49 are as follows:
$miss_tot = mysql_result($result1,$i,"(miss_no)");
$hours_tot = mysql_result($result1,$i,"(miss_hours)");
I put the select statement you provided as a second. using the $query1
and $result1 variable.
Re: Help with COUNT() on a php form
am 10.01.2006 20:43:42 von Shion
bigsamurai wrote:
> now i get this error...
>
> Warning: mysql_result(): supplied argument is not a valid MySQL result
> resource in /home/content/m/i/k/mikey05156/html/ind_pilotins.php on
> line 48
>
> Warning: mysql_result(): supplied argument is not a valid MySQL result
> resource in /home/content/m/i/k/mikey05156/html/ind_pilotins.php on
> line 49
>
> line 48 and 49 are as follows:
>
>
> $miss_tot = mysql_result($result1,$i,"(miss_no)");
> $hours_tot = mysql_result($result1,$i,"(miss_hours)");
>
>
> I put the select statement you provided as a second. using the $query1
> and $result1 variable.
>
$row=mysql_featch_arrya($result1)
$query = "SELECT mission.miss_pilot_assign,
pilot.pilot_no, pilot.pilot_name,
mission.miss_status,
mission.miss_no,
mission.miss_hours
FROM mission, pilot
WHERE
mission.miss_pilot_assign=pilot.pilot_no
AND
mission.miss_status=3
AND
pilot.pilot_name='$_POST[pilot_name]'
GROUP
by mission.miss_status";
$result=@mysql_query($query);
$number = mysql_numrows($result);
if ($number > 0) {
print "
Here are the flight statistics for '$_POST[pilot_name]'as
recorded by Squadron Operations.
";
print "";
print "";
print "
face=Arial color=#FFFFFF size=2>Number of missions | ";
print "
face=Arial color=#FFFFFF size=2>Number of Hours | ";
print "
";
/* Get pilots info */
while($row=mysql_fetch_array($result)) {
print "";
print "
face=Arial size=2 color=#FFFFFF>".$row[4]." | ";
$tot_miss+=$row[4];
print "
face=Arial size=2 color=#FFFFFF>".row[5]." | ";
print "
";
$tot_hours+=$row[5];
}
print "";
print "
face=Arial size=2 color=#FFFFFF>$tot_miss | ";
print "
face=Arial size=2 color=#FFFFFF>$tot_hours | ";
print "
";
print "
";
}
/* Close the database connection */
mysql_close();
?>
Re: Help with COUNT() on a php form
am 11.01.2006 09:52:05 von Jim Michaels
since you are using mysql_fetch_array you can always use column names
instead of column numbers for an index into the row array. mnemonics are
easier to read and debug.
"J.O. Aho" wrote in message
news:42ih3fF1ieremU1@individual.net...
> bigsamurai wrote:
>> now i get this error...
>>
>> Warning: mysql_result(): supplied argument is not a valid MySQL result
>> resource in /home/content/m/i/k/mikey05156/html/ind_pilotins.php on
>> line 48
>>
>> Warning: mysql_result(): supplied argument is not a valid MySQL result
>> resource in /home/content/m/i/k/mikey05156/html/ind_pilotins.php on
>> line 49
>>
>> line 48 and 49 are as follows:
>>
>>
>> $miss_tot = mysql_result($result1,$i,"(miss_no)");
>> $hours_tot = mysql_result($result1,$i,"(miss_hours)");
>>
>>
>> I put the select statement you provided as a second. using the $query1
>> and $result1 variable.
>>
>
> $row=mysql_featch_arrya($result1)
>
> $query = "SELECT mission.miss_pilot_assign,
> pilot.pilot_no, pilot.pilot_name,
> mission.miss_status,
> mission.miss_no,
> mission.miss_hours
> FROM mission, pilot
> WHERE
> mission.miss_pilot_assign=pilot.pilot_no
> AND
> mission.miss_status=3
> AND
> pilot.pilot_name='$_POST[pilot_name]'
> GROUP
> by mission.miss_status";
>
>
> $result=@mysql_query($query);
>
> $number = mysql_numrows($result);
>
> if ($number > 0) {
> print " Here are the flight statistics for '$_POST[pilot_name]'as
> recorded by Squadron Operations.
";
>
> print "";
>
> print "";
> print "
> face=Arial color=#FFFFFF size=2>Number of missions | ";
> print "
> face=Arial color=#FFFFFF size=2>Number of Hours | ";
> print "
";
>
> /* Get pilots info */
> while($row=mysql_fetch_array($result)) {
> print "";
> print "
> face=Arial size=2 color=#FFFFFF>".$row[4]." | ";
> $tot_miss+=$row[4];
>
> print "
> face=Arial size=2 color=#FFFFFF>".row[5]." | ";
> print "
";
> $tot_hours+=$row[5];
>
> }
>
> print "";
> print "
> face=Arial size=2 color=#FFFFFF>$tot_miss | ";
>
> print "
> face=Arial size=2 color=#FFFFFF>$tot_hours | ";
> print "
";
>
> print "
";
> }
>
>
>
>
> /* Close the database connection */
> mysql_close();
> ?>