Jump to content

[SOLVED] Need a little help


topflight

Recommended Posts

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

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>
<? } ?>
<? } ?>

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~";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.