mattia Posted May 20, 2012 Report Posted May 20, 2012 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 Quote
mattia Posted May 20, 2012 Author Report Posted May 20, 2012 echo 0 I is not did no flying today Quote
freshJet Posted May 21, 2012 Report Posted May 21, 2012 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 Quote
Moderators Kyle Posted May 21, 2012 Moderators Report Posted May 21, 2012 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; } ?> Quote
mattia Posted May 21, 2012 Author Report Posted May 21, 2012 Hi kyle hi itrobb thanks for your help but it does not work, the result is always 0, but I have to change dmy in the code? Quote
freshJet Posted May 21, 2012 Report Posted May 21, 2012 Woops I didn't mean that $pilotid. Hang on I'll test it out. Quote
freshJet Posted May 21, 2012 Report Posted May 21, 2012 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); ?> Quote
mattia Posted May 21, 2012 Author Report Posted May 21, 2012 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 Quote
freshJet Posted May 21, 2012 Report Posted May 21, 2012 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; ?> Quote
mattia Posted May 21, 2012 Author Report Posted May 21, 2012 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; ?> Quote
freshJet Posted May 21, 2012 Report Posted May 21, 2012 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. Quote
mattia Posted May 21, 2012 Author Report Posted May 21, 2012 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 Quote
mattia Posted May 21, 2012 Author Report Posted May 21, 2012 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 Quote
freshJet Posted May 21, 2012 Report Posted May 21, 2012 Erm, are you sure that the pilot has flown any flights? Quote
mattia Posted May 21, 2012 Author Report Posted May 21, 2012 you've tried it on me, look at my badge below Quote
Guest lorathon Posted May 21, 2012 Report Posted May 21, 2012 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. Quote
mattia Posted May 21, 2012 Author Report Posted May 21, 2012 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 Quote
Guest lorathon Posted May 21, 2012 Report Posted May 21, 2012 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); Quote
mattia Posted May 21, 2012 Author Report Posted May 21, 2012 now works, thanks a lot for your help jeff and itrobb, you are great problem solved Quote
flyalaska Posted May 22, 2012 Report Posted May 22, 2012 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 Quote
Guest lorathon Posted May 22, 2012 Report Posted May 22, 2012 After code add echo $pireps->total; Quote
flyalaska Posted May 22, 2012 Report Posted May 22, 2012 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; ?> Quote
Guest lorathon Posted May 22, 2012 Report Posted May 22, 2012 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.