Jump to content

PHP/MySQL Problem...


hellouthere

Recommended Posts

I have a script that basically displays data from 2 seperate mysql tables, it also performs an on-the-fly sum of all records of time (in the format 00:00) for each person in the database, i can assure you that all the table names are correct and the display shows all the information but gives an error for the on-the-fly calculation, the script is adapted from another script i have written but im not sure what ive missed... the script follows...

 

<?php

$hostName = "localhost";
$userName = "root";
$password = "london2012";
$dbName = "flkeeper";

$connect = @mysql_connect($hostName, $userName, $password);

$select = @mysql_select_db($dbName);


$query = "SELECT * FROM pilots";

$result = mysql_query($query);

$number = mysql_numrows($result);

if ($number > 0) {
print "<table width=925px border=1><tr bgcolor=#336699><td><div class=style1 align=center style=color:#ffffff><strong style=font-size:12px>Crew Roster</strong></div></td></tr></table>";
print "<table width=925px border=1><tr bgcolor=#336699><td width=174px><div align=center><strong><span style=color:#ffffff class=style1>Name</span></strong></div></td><td width=121px><div align=center><strong><span style=color:#ffffff class=style1>Pilot ID / <br> Callsign</span></strong></div></td><td width=59px><div align=center><strong><span style=color:#ffffff class=style1>HUB</span></strong></div></td><td width=90px><div align=center><strong><span style=color:#ffffff class=style1>Flight <br> Time</span></strong></div></td><td width=155px><div align=center><strong><span style=color:#ffffff class=style1>Awards</span></strong></div></td><td width=140px><div align=center><strong><span style=color:#ffffff class=style1>Last Flight</span></strong></div></td><td width=152px><div align=center><strong><span style=color:#ffffff class=style1>Status</span></strong></div></td></tr></table>";
print "<table width=925px border=1>";

for ($i=0; $i<$number; $i++) {
     		$name = mysql_result($result,$i, "realname");
	$id = mysql_result($result,$i, "ID");

	$query_hours = "SELECT sec_to_time(sum(time_to_sec(t2.BlockTime))) AS duration_sum FROM pilots t1, liveacars t2 WHERE t1.ID=$id AND t1.ID=t2.IDPilot";
    		$result_hours = mysql_query($query_hours);
    	
    		if (mysql_num_rows($result_hours) > 0) {
		$time = mysql_result($result_hours,0,"duration_sum");
	}

print "<tr>";
print "<td width=174px>$name</td>";
print "<td width=121px>$id</td>";
print "<td width=59px>hub</td>";
print "<td width=90px>$time</td>";
print "<td width=155px>awards</td>";
print "<td width=140px>last flight</td>";
print "<td width=152px>IVAO indicator</td>";
print "</tr>";
}
print "</table>";

print "<table width=925px border=1>";
print "<tr>";
print "<td bgcolor=#336699> </td>";
print "</tr>";
print "</table>";

}

mysql_close();
?>

 

Id be very grateful of a solution or even a push in the right direction, Thanks for your time...

Link to comment
Share on other sites

I can offer a push in the right direction.

 

Start by removing all the @ from your functions.  All @ does is hide errors from you.  Instead, write them like this:

 

$connect = mysql_connect($hostName, $userName, $password) or die("Couldn't connect to database");

 

Do the same for mysql_select_db() and for EVERY call to mysql_query().  For mysql_query(), do it like this

$query = "SELECT * FROM pilots";

$result = mysql_query($query) or die("Error in $query\n" . mysql_error());

 

But do NOT use "or die" with mysql_result() or mysql_num_rows().  Leave those as they are.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.