1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Alert System - displaying 9

Discussion in 'PHP' started by Jeremy Benson, Jun 5, 2014.

  1. #1
    Hey,

    I'm working on my alert system, but lack of knowledge in foreach, and best possible way is hitching me. Basically I have three or four different kinds of alerts. 9 can fit on a page. I'm using a foreach to loop through them to get them onto the page. After that I'm not sure. That's where it's confusing. I could use JS to count them and once they're all deleted refresh the page and nine more will load, lol. That's what I was thinking... ahh. Anyway. My foreach is below... Where I try to give $sender a value, that block doesn't fire.

    
    foreach($retrievedAlerts as $L1)
                 { foreach($L1 as $L2 => $value)
                   {   
                   // Only nine alerts displayed on a page.
                     if($L1 != 10)
                     {
                       //Display outline for friend requests.
                       if($L2 === 'type' && $value === "friend request")
                       {   
                         $retrievedMime = [];
                         $sender = "";
                         //Extract sender
                         
                         if($L2 === 'from')
                         {
    
                             //Bug, doesn't fire.
                             $sender = $value;
                         }
                         //Test if posting user has profile image
                         
                         $retrieveMime = $dbConnect->prepare("SELECT `profileImageMime` FROM `profileSettings` WHERE `handle` = ?");
                         
                         try{
                         
                           $retrieveMime->execute([$sender]);
                           $retrievedMime = $retrieveMime->fetch();
                       
                         }catch(\PDOException $e){  }
                       
                       
                         echo "<div id=\"alertwrapper\" style=\"height:62px; width:400px; margin-bottom:12px; padding:4px;\">\n"
                        . "\t\t\t\t<div id=\"alertimage\" style=\"background-color:blue; height:62px; width:62px; float:left;\">\n";
                           
                           if(!empty($retrievedMime))
                           {
                               echo "\t\t\t\t\t\t<img alt=\"alertpic1\" src=\"users/" . $sender . "/images/profile" . $retrievedMime[0] . "/" . "style=\"background-color:blue;height:62px; width:62px;\" />\n";
                           
                           }else{
                           
                             echo "\t\t\t\t\t\t<img alt=\"alertpic1\" src=\"system/images/profile/stockprofile.jpg\" style=\"background-color:blue;height:62px; width:62px;\" />\n";
                           }
                           
                           echo "\t\t\t\t</div>\n"
                           . "\t\t\t\t<div>\n"
                           . "\t\t\t\t\t<span>&nbsp;Handle:" . $sender;
                                                 
                           echo  "\t\t\t\t\t</span><span></span><br />\n"
                             . "\t\t\t\t\t<span>&nbsp;Message:Friend Request</span><span></span><br />\n"
                             . "\t\t\t\t\t<span>&nbsp;<a>accept</a></span>"
                             . "\t\t\t\t\t<span style=\"margin-left:8px;\">"
                             . "\t\t\t\t\t<a>deny</a></span>\n"
                             . "\t\t\t\t</div>\n"
                             . "\t\t\t</div>\n";
                         }                 
                       }
                     
                     }
    
    PHP:
     
    Jeremy Benson, Jun 5, 2014 IP