mavveton12 Posted January 17, 2013 Share Posted January 17, 2013 How doi do this in php Please help foreach account if adfundnotificicationdata exists if adfund is lower than threshold && current notificationdata is higher than threshold sendmail... update notificationdata... else insert new data Quote Link to comment https://forums.phpfreaks.com/topic/273273-php-beginner-foreach-loop/ Share on other sites More sharing options...
Muddy_Funster Posted January 17, 2013 Share Posted January 17, 2013 have you checked the manual pages on foreach()? Without some contextual information about what each of these statements and parameters are no one can give you an accurate translation of your psudo-code. Also, if you are thinking about getting into programming, I suggest you have a look here http://en.wikipedia.org/wiki/CamelCase Quote Link to comment https://forums.phpfreaks.com/topic/273273-php-beginner-foreach-loop/#findComment-1406392 Share on other sites More sharing options...
mavveton12 Posted January 17, 2013 Author Share Posted January 17, 2013 Thanks man i will look into to it, I just need a little help, an example how you would write foreach for this example. I have just finished the sql query. Quote Link to comment https://forums.phpfreaks.com/topic/273273-php-beginner-foreach-loop/#findComment-1406402 Share on other sites More sharing options...
Muddy_Funster Posted January 17, 2013 Share Posted January 17, 2013 again, without knowing what each "thing" is it's not really possible to give an accurate example. A generic example would somthing along the lines of foreach($topLevelArray as $subArray){ if(!isset($subArray['arrayKeyToCheck'] || empty($subArray['arrayKeyToCheck'])){ runDataInsertFunction($subArray); } elseif(($subArray['nextKeyToCheck'] < $valueToCheckAgainst) && ($subArray['lastKeyToCheck'] > $valueToCheckAgainst)){ sendEmailFunction($subArray); } else{ runErrorFunction($errorDetails); } } This is just a simplified version that is half way between your psudo-code and the actual code you would use and is assuming a multi-dimensional array as the initial $topLevelArray. Quote Link to comment https://forums.phpfreaks.com/topic/273273-php-beginner-foreach-loop/#findComment-1406410 Share on other sites More sharing options...
mavveton12 Posted January 17, 2013 Author Share Posted January 17, 2013 Thanks man this was alot help man! iam trying to complete Cron job task to notify users about low ad funds Do u think i can complete it with your solution that u sent me public function adFundNotificationTask() { $SQL = array( 'findAdFundLowNotificationActive' => "SELECT a.accountId, a.publisherId FROM Account a WHERE a.adFundNotificationActive = true AND a.accountState in ('ACTIVE','ACTIVE_OBSERVATION')", 'findAdfundsByAccount' => "SELECT accountId, adFund FROM Account", 'findAdfunsNotificationData' => "SELECT accountId, amount FROM Account_Ad_Fund_Notification_Task", ); foreach($topLevelArray as $subArray){ if(!isset($subArray['arrayKeyToCheck'] || empty($subArray['arrayKeyToCheck'])){ runDataInsertFunction($subArray); } elseif(($subArray['nextKeyToCheck'] < $valueToCheckAgainst) && ($subArray['lastKeyToCheck'] > $valueToCheckAgainst)){ sendEmailFunction($subArray); } else{ runErrorFunction($errorDetails); } } Quote Link to comment https://forums.phpfreaks.com/topic/273273-php-beginner-foreach-loop/#findComment-1406417 Share on other sites More sharing options...
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.