DiStefano Posted July 1, 2009 Share Posted July 1, 2009 Hi, First of all, good to be here! Second, the problem with which I am struggeling... I would like to use a shoutbox script on my website in which I can style the final 3 comments. The script that I found does call for the last comment seperately, but I would like to know how I can call the for last and the one before that. Here is the part of the script that uses $LastID (which is the final comment posted) <?php $first_time = true; ?> <?php foreach ($list as $item) : ?> <?php if ($first_time == true): $lastID = $item->id; ?> <div id="lastMessage"><span> <?php echo $item->text; ?> </span></div><ul id="outputList"> <?php endif; ?> <?php endforeach; ?> and here is the part that I believe defines $LastID: function getAjaxShouts($shouts) { global $mainframe; $db =& JFactory::getDBO(); $user =& JFactory::getUser(); $maydelete = $user->authorize('com_content', 'edit', 'content', 'all'); $jal_lastID = JRequest::getVar( 'jal_lastID', 0 ); $query = 'SELECT * FROM #__shoutbox WHERE id > '.$jal_lastID.' ORDER BY id DESC'; $db->setQuery( $query , 0 , $shouts); $rows = $db->loadObjectList(); $i = 0; $shouts = array(); foreach ( $rows as $row ) { $shouts[$i]->id = $row->id; $shouts[$i]->name = $row->name; $shouts[$i]->text = $row->text; $shouts[$i]->text = preg_replace( "`(http|ftp)+(s)?:(//)((\w|\.|\-|_)+)(/)?(\S+)?`i", "<a href=\"\\0\">«link»</a>", $shouts[$i]->text); $shouts[$i]->text = preg_replace("`([-_a-z0-9]+(\.[-_a-z0-9]+)*@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]{2,6})`i","<a href=\"mailto:\\1\">«email»</a>", $shouts[$i]->text); $mainframe->triggerEvent('onBBCode_RenderText', array (& $shouts[$i]->text) ); $mainframe->triggerEvent('onSmiley_RenderText', array (& $shouts[$i]->text) ); if($maydelete) $shouts[$i]->text = $shouts[$i]->text.' <a href="?mode=delshout&shoutid='.$shouts[$i]->id.'" title="Delete">x</a>'; $shouts[$i]->url = $row->url; $shouts[$i]->id = $row->id; $shouts[$i]->time = $row->time; $i++; } return $shouts; } Now my question is how would I call the ID before the last one and also the one before that. So that I can call them in the form: $forlastID = $item->id; ?> Hope somebody can help, because I am clueless like Shaggy and Scooby before the commercial break! Greetings, Fabian Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 1, 2009 Share Posted July 1, 2009 It looks to me like the Last ID is defined in the first block of code when looping through the object $list. Here is one methods I can think of to get the last three values. Set the value for last id and the other two IDs on each iteration of the loop. I'll give an example in PHP but you will have to modify for your specific framework $lastID = false; $secondLastID = false; $thirdLastID = false; foreach($list as $item) { $thirdLastID = $secondLastID; $secondLastID = $lastID; $lastID = $item->id; } Quote Link to comment Share on other sites More sharing options...
DiStefano Posted July 2, 2009 Author Share Posted July 2, 2009 Thanks for the reply, but I don't really understand what you mean. I thought the $LastID was defined in the second block, because there it says something that it will be ID 0 when the query is called in the descending order. I was thinking in the order of defining the $secondLastID as the $LastID +1 or am I now thinking really stupid. I don't really see how I can modify your explenation so the the $secondLastID will be the shout before the last on and my $thirdLastID will always be the shout before that. Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 2, 2009 Share Posted July 2, 2009 Don't know what to tell you. The first block of code has a loop which defines a value for the variable $lastID on each iterration of the loop. So, when the loop completes $lastID will equal the ID of the last item in the loop. That's pretty strait forward. What is not clear is how that variable is used later - but I suspect that is the variable used to find the last record. The second block of code is defining a variable called $jal_lastID like this: $jal_lastID = JRequest::getVar( 'jal_lastID', 0); You are using some type of PHP framework/class instead of just plain old PHP, so I have no idea what that is doing. Quote Link to comment 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.