Jump to content

how many flights did today a pilot[SOLVED]


mattia

Recommended Posts

hi all boys

I created this code to see, (in pilot_public_profile.tpl,) how many flights did today a pilot, but does not work. the result is always 0

<?php
$query = 'SELECT COUNT(*) AS total FROM '.TABLE_PREFIX.'pireps
WHERE submitdate >= NOW() -172800
AND pilotid = $userinfo->pilotid
';
					$result=DB::get_row($query);
					if (!$result){
						echo 0;
					}
					else {
						echo $result->total;
}
?>

Can you help me to understand why?? thank you very much :)

Link to comment
Share on other sites

  • Moderators

spotted a few errors there itrobb, no worries, I see your trying to learn.

try this, it should work, lol. Coded from my phone.

<?php
$query = 'SELECT COUNT(*) AS total FROM '.TABLE_PREFIX.'pireps
WHERE submitdate < dmy
AND pilotid = {$userinfo->pilotid}';
											$result=DB::get_row($query);
											if (!$result){
													echo '0';
											}
											else {
													echo $result->total;
	}
?>

Link to comment
Share on other sites

This may or most likely won't work:

<?php
$pilotid = $userinfo->pilotid;
$pireps = getAllReportsForPilot($pilotid);
$today = date('Y-m-d');

if(($pireps->submitdate) == $today)
{
echo $pireps;
}
else
{
continue;
}
?>

OR


<?php
$query = 'SELECT COUNT(*) AS total FROM '.TABLE_PREFIX.'pireps
WHERE submitdate < dmy
AND pilotid = {$userinfo->pilotid}';

$result = DB::get_row($query);
$flightstoday = count($result);
?>

Link to comment
Share on other sites

I know what's wrong:

<?php
$pilotid = $userinfo->pilotid;
$pireps = PIREPData::getAllReportsForPilot($pilotid);
$today = date('Y-m-d');

if(($pireps->submitdate) == $today)
{
echo $pireps;
}
else
{
continue;
}
?>

AND

<?php
$query = 'SELECT COUNT(*) AS total FROM '.TABLE_PREFIX.'pireps
WHERE submitdate < date('Y-m-d');
AND pilotid = {$userinfo->pilotid}';

$result = DB::get_row($query);
$flightstoday = count($result);

echo $flightstoday;
?>

Link to comment
Share on other sites

thanks itrobb but still does not work

for the first code appears error this

Fatal error: Cannot break/continue 1 level in /var/www/virtual/italianivolanti.it/htdocs/iv/core/templates/pilot_public_profile.tpl on line 96


<?php
$pilotid = $userinfo->pilotid;
$pireps = PIREPData::getAllReportsForPilot($pilotid);
$today = date('Y-m-d');

if(($pireps->submitdate) == $today)
{
echo $pireps;
}
else
{
continue;---this is line 96
}
?>

for the second code appears error this

Parse error: syntax error, unexpected T_STRING in /var/www/xxxxxxxxxx/templates/pilot_public_profile.tpl on line 87

<?php
$query = 'SELECT COUNT(*) AS total FROM '.TABLE_PREFIX.'pireps
WHERE submitdate < date('Y-m-d');--------------this is line 87
AND pilotid = {$userinfo->pilotid}';

$result = DB::get_row($query);
$flightstoday = count($result);

echo $flightstoday;
?>



Link to comment
Share on other sites

OK try removing the continue in the first one so it's just else { }. For the second, try :

<?php
$today = date('Y-m-d')
$query = 'SELECT * FROM '.TABLE_PREFIX.'pireps
WHERE submitdate < $date;
AND pilotid = {$userinfo->pilotid}';

$result = DB::get_row($query);
$flightstoday = count($result);

echo $flightstoday;
?>

Actually I'm not so sure about this one because I don't know if you can put the php date into SQL.

Link to comment
Share on other sites

thanks but dont work

this error

Parse error: syntax error, unexpected T_VARIABLE in /var/xxxxxxx/pilot_public_profile.tpl on line 87

<?php
$today = date('Y-m-d')
$query = 'SELECT * FROM '.TABLE_PREFIX.'pireps ------this is line 87
WHERE submitdate < $date;
AND pilotid = {$userinfo->pilotid}';

$result = DB::get_row($query);
$flightstoday = count($result);

echo $flightstoday;
?>

many thanks for your help sir

Link to comment
Share on other sites

ok i find the error but dont'work the result is 0

<?php
$date = date('d-m-Y');
$query = 'SELECT * FROM '.TABLE_PREFIX.'pireps
WHERE submitdate < $date;
AND pilotid = {$userinfo->pilotid}';

$result = DB::get_row($query);
$flightstoday = count($result);

echo $flightstoday;
?>

is very difficult this code

Link to comment
Share on other sites

Guest lorathon

Try this. I use something similar so it should work but not guarantees.



$sql = 'SELECT
          COUNT(*) as total
          FROM '.TABLE_PREFIX.'pireps 
          WHERE `pilotid` = '.$pilotid.'
          AND DATE(`submitdate`) = NOW()
          ';

$pireps = DB::get_row($sql);

// $pireps->total = Total count of pireps filed today.

Link to comment
Share on other sites

Guest lorathon

Change NOW() to CURDATE()

I checked and it works fine now.


$sql = 'SELECT
            COUNT(*) as total
            FROM '.TABLE_PREFIX.'pireps
            WHERE `pilotid` = '.$pilotid.'
            AND DATE(`submitdate`) = CURDATE()
            ';

$pireps = DB::get_row($sql);

Link to comment
Share on other sites

Guest lorathon

What are you sticking into the $pilotid? Dis the pilot attached to the pilotid fly today?

Try this and read the comments


$pilotid = XXXX  //Modify the XXXX to a pilot id.  Or tie it into the template like Auth::$pilotid

$sql = 'SELECT
		 COUNT(*) as total
		 FROM '.TABLE_PREFIX.'pireps
		 WHERE `pilotid` = '.$pilotid.'
		 AND DATE(`submitdate`) = CURDATE()
		 ';

$pireps = DB::get_row($sql);

echo $pireps->total;  ?? This should echo the total number of pireps counted that where filed today

echo "<br/><br/>"; // Just echo some spacing to allow you to read the difference from above to below

print_r($pireps); //This will dump all info inside of the array

Link to comment
Share on other sites

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.

Loading...
×
×
  • Create New...