Jump to content

Recommended Posts

Posted

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 :)

Posted

Try this

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

Not sure though

  • Moderators
Posted

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

Posted

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);
?>

Posted

hi itrobb

thanks for help.....for the first code appears error this

Fatal error: Call to undefined function getAllReportsForPilot() in /varxxxxxxxxxxxxxxxx/templates/pilot_public_profile.tpl on line 87

for the second code nothing appears

Posted

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

Posted

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



Posted

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.

Posted

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

Posted

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

Guest lorathon
Posted

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.

Posted

hi jeff, thanks for your interest

I tried your code but not working, there is no result I cannot understand the problem, the code is right

Thank you all for your help guys

Guest lorathon
Posted

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);

Posted

I tried that code

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

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

returns a blank, not a number

Posted

If you mean like this, I still get a blank response.

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

$pireps = DB::get_row($sql);
?>
<?php echo $pireps->total; ?>

Guest lorathon
Posted

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

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