topflight Posted March 24, 2009 Share Posted March 24, 2009 I am trying to add integers from to different querys. First I have a query goes to the hour table and add up all the hours where the ID = $id and then I have a query goes to the main database and get the transfer hours so now I have both of those variables set and I would like to add both of them but for some reason I keep getting a result of 15 here is the code. $hour1 = " SELECT sum( dur )FROM hours WHERE login = '$gl' "; $hour1r = mysql_query($hour1); $hour2 = " SELECT thours FROM members WHERE login = '$gl' LIMIT 0 , 30 "; $hour2r = mysql_query($hour2); Link to comment https://forums.phpfreaks.com/topic/150973-solved-need-a-little-help/ Share on other sites More sharing options...
MadTechie Posted March 24, 2009 Share Posted March 24, 2009 Okay your getting 15 but expect what ? also on $hour2 your not using sum so i assume you have a loop.. as you havn't posted any of your results code its kinda hard to say what the problem is! Link to comment https://forums.phpfreaks.com/topic/150973-solved-need-a-little-help/#findComment-793166 Share on other sites More sharing options...
topflight Posted March 24, 2009 Author Share Posted March 24, 2009 I didn't loop should I loop u think? If so can have an example of the proper loop thanks. Link to comment https://forums.phpfreaks.com/topic/150973-solved-need-a-little-help/#findComment-793173 Share on other sites More sharing options...
topflight Posted March 25, 2009 Author Share Posted March 25, 2009 any other suggestions? Link to comment https://forums.phpfreaks.com/topic/150973-solved-need-a-little-help/#findComment-793330 Share on other sites More sharing options...
Yesideez Posted March 25, 2009 Share Posted March 25, 2009 I agree with Techie here - more code would be a bit more helpful as we can't see how you're manipulating the data after you retrieve it from the database. The error could be anywhere - even behind you Link to comment https://forums.phpfreaks.com/topic/150973-solved-need-a-little-help/#findComment-793405 Share on other sites More sharing options...
topflight Posted March 25, 2009 Author Share Posted March 25, 2009 this is my code <?php if(isset($_GET['login'])){ $gl = $_GET['login']; include 'db.php'; $sql = "SELECT * FROM pilots WHERE login = '{$_GET['login']}'"; $query = mysql_query($sql) or die("Problem with the query: $sql<br>" . mysql_error()); $query = mysql_query($sql); $loginc = mysql_num_rows($query); if($loginc == 0){echo'Pilot ID does not exists in database';} else if (mysql_num_rows($query) > 0) { $data = mysql_fetch_assoc($query); $login = $data["login"]; $status =$data["status"]; $hm = $data["hm"]; $ed = $data["ed"]; $bm = $data["bm"]; $hr = $data["hr"]; $active = $data["active"]; $semail = $data["semail"]; $email = $data["email"]; $about = $data["about"]; $hour1 = " SELECT sum( dur )FROM pirep WHERE login = '$gl' "; $hour1r = mysql_query($hour1); $hour2 = " SELECT thours FROM pilots WHERE login = '$gl' LIMIT 0 , 30 "; $hour2r = mysql_query($hour2); $fhour = '$hour2r' + '$hour1r'; if($loginc == 0){echo'Pilot ID does not exists in database';} else { ?><title><?php echo "{$data["fname"]}";?> <? echo "{$data["lname"]}"?> Simulated Alaska Profile</title> <body link="#0066FF" vlink="#0066FF" alink="#0066FF"> <font size="4" color="#0066CC"> <center> Pilot Information Card </center></font> <? // to change the table back to ctr just change allin to ctr ?> <table width="60%" border="0" cellspacing="0" cellpadding="1" align="left"> <tr> <th width="27%" scope="row"><div align="left">Pilot ID</div></th> <td width="73%"><?php echo "{$data["login"]}"?></td> </tr> <tr> <th scope="row"><div align="left">Pilot Name</div></th> <td><?php echo "{$data["fname"]}";?> <? echo "{$data["lname"]}"?></td> </tr> <tr> <th scope="row"><div align="left">Hub</div></th> <td><?php echo "{$data["hub"]}"?></td> </tr> <tr> <th height="23" scope="row"><div align="left">Status</div></th> <td><?php if($status == 2){ echo'<font color="#FF0000">Suspended</font Color>';} if($active == 1){ echo'<font color="#6cbafc">Active</font Color>';} if($status == 3){ echo'<font color="#6cbafc">LOA</font Color>';}?> </td> </tr> <tr> <th height="23" scope="row"><div align="left">Rating</div></th> <td><?php echo "{$data["rating"]}"?></td> </tr> <tr> <th scope="row"><div align="left">Date Hired </div></th> <td><?php echo "{$data["date"]}"?></td> </tr> <tr> <th scope="row"><div align="left">Current Hours </div></th> <td><?php echo "$fhour";?></td> </tr> <tr> <th scope="row"><div align="left">Email</div></th> <td><?php if($semail == 1){ echo"$email";} elseif ($semail == 0) { echo'Email Hidden '; }?></td> </tr> <tr> <th scope="row"><div align="left">Staff Member</div></th> <td><?php if($hm == 1){ echo'Hub Manager';} elseif ($hr == 1){ echo'Human Resources Officer';} elseif ($bm == 1){ echo'Board Member';} elseif ($ed==1){echo'Events Director';} else { echo'Not Apart Of Staff';}?></td> </tr> </tr> <div align="left"></div> <tr> <th height="23" scope="row"><div align="left"><?php echo "{$data["fname"]}";?>'s Bio</div></th> <td><?php echo "{$data["about"]}"?></td> </tr> </table> <p> <? } ?> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <table width="25%" border="0" cellspacing="0" cellpadding="1" align="center"> <tr> <th scope="row"><div align="center"><A HREF="http://vataware.com/pilot.cfm?cid=<?php echo "{$data["vatsimid"]}"?> " ><font color="#0099CC">Vataware Stats for <?php echo "{$data["fname"]}"?> </A></div></th> </tr> </table> <hr align="center"> <font size="5" color="#0066CC"><center><?php echo "{$data["rating"]}"?> <?php echo "{$data["lname"]}"?> Latest Flights</center></font> <p> <?php } ?> <? $psql = "SELECT * FROM pirep WHERE login = '{$_GET['login']}' and paccpt > '0' ORDER BY `date` DESC LIMIT 7 "; $pquery = mysql_query($psql) or die("Problem with the query: $sql<br>" . mysql_error()); $pquery = mysql_query($psql); $plic = mysql_num_rows($pquery); if($plic ==0){echo'';}else{ ?> <table width="100%" cellpadding="3" align="CENTER"> <tr bgcolor=#EEEEEE> <td width="25%">Callsign</td> <td width="20%">Deparure Airport</td> <td width="20%">Arrival Airport</td> <td width="60%">Aircraft</td> </tr> <? if($pquery){ while ($result = mysql_fetch_assoc($pquery)) { ?> <tr bgcolor=#EEEEEE> <tr style="background-color:#EAEAEA;" onMouseOver="this.style.backgroundColor='#0099FF'" onMouseOut="this.style.backgroundColor='#EAEAEA'"> <td><a href="?page=viewpireps&prid=<?php echo "{$result["prid"]}"?>&l=<?php echo "{$data["login"]}"?>&ln=<?php echo "{$data["lname"]}"?>&fn=<? echo"{$data["fname"]}"?>"><? echo"{$result['callsign']}"?></a> <td><?php echo "{$result["dep"]}"?></td> <td><?php echo "{$result["arr"]}"?></td> <td><?php echo "{$result["ac"]}"?></td> </tr> <?php } } ?> </table> <? } ?> <? } ?> Link to comment https://forums.phpfreaks.com/topic/150973-solved-need-a-little-help/#findComment-794048 Share on other sites More sharing options...
topflight Posted March 26, 2009 Author Share Posted March 26, 2009 ? anything? Link to comment https://forums.phpfreaks.com/topic/150973-solved-need-a-little-help/#findComment-794221 Share on other sites More sharing options...
MadTechie Posted March 26, 2009 Share Posted March 26, 2009 Okay i don't understand why you have a limit on your $hour2 query (read comment) <?php $hour1 = " SELECT sum( dur ) as H FROM pirep WHERE login = '$gl' "; $hour1r = mysql_query($hour1); $hour1d = mysql_fetch_assoc($hour1r); //No idea Why your limiting to 30 here but i'll assume theirs more than one! $hour2 = " SELECT thours FROM pilots WHERE login = '$gl' LIMIT 0 , 30 "; $hour2r = mysql_query($hour2); $fhour = $hour1d['H']; while($hour2d = mysql_fetch_assoc($hour2r)) { $fhour += $hour2d['thours']; } echo "~$fhour~"; ?> Link to comment https://forums.phpfreaks.com/topic/150973-solved-need-a-little-help/#findComment-794397 Share on other sites More sharing options...
topflight Posted March 26, 2009 Author Share Posted March 26, 2009 thanks Link to comment https://forums.phpfreaks.com/topic/150973-solved-need-a-little-help/#findComment-794508 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.