hellouthere Posted February 28, 2007 Share Posted February 28, 2007 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 https://forums.phpfreaks.com/topic/40594-phpmysql-problem/ Share on other sites More sharing options...
btherl Posted March 1, 2007 Share Posted March 1, 2007 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 https://forums.phpfreaks.com/topic/40594-phpmysql-problem/#findComment-196561 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.