FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Emoticon System Help





ddukki
I'm trying to make an Emoticon table for my forums but I can't seem to figure out how to do it. I have an array with the keys being the emoticon code, and then the filename for the actual value.

ex.
Code:

$emoticonarray = array(
':^_^:'  => '^_^.gif',
':anywayz:'  => 'anywayz.gif',
':aww:'  => 'aww.gif',
':blush:'  => 'blush.gif',
':eek:'  => 'eek.gif')


I want to be able to make a table that shows all these emoticons in a couple of rows. I can get it to make one row using a foreach/as function, but I don't know how to make it make a new row every five or so emoticons. Is there a way to do this?
hexkid
ddukki wrote:
I want to be able to make a table that shows all these emoticons in a couple of rows. I can get it to make one row using a foreach/as function, but I don't know how to make it make a new row every five or so emoticons. Is there a way to do this?


Not automatically, no. You have to count the emoticons and start a new row every five or so of them
Code:
<?php
define('EMOTICONS_PER_ROW', '5');
$count = 0;
echo '<table><tr>';
foreach(range(1, 42) as $v) { // example, instead of emoticons
  echo "<td>$v</td>";
  if (++$count == EMOTICONS_PER_ROW) {
    $count = 0;
    echo '</tr><tr>';
  }
}
// fill last row with spaces
while ($count++ < EMOTICONS_PER_ROW) echo '<td>&nbsp;</td>';
echo '</tr></table>';
?>


With this code you will end up with a final row completely filled with blanks if the number of emoticons you have is a multiple of EMOTICONS_PER_ROW. I'm sure there is a easy way to avoid that but I'm not in the mood to think about that now Wink
ddukki
Thank you SO MUCH. I got the smilies to work beautifully. I didn't mean that kind of table, but thank you for being so thorough, it helped a lot. I edited some of the code, if you don't mind, but THANK YOU!!!
hexkid
ddukki wrote:
Thank you SO MUCH. I got the smilies to work beautifully. I didn't mean that kind of table, but thank you for being so thorough, it helped a lot. I edited some of the code, if you don't mind, but THANK YOU!!!
You're very welcome. Of course my code was meant to be edited Wink

After a good night sleep I came up with a new and better version, using array_splice() instead of counting values (but I still count for the last row).
Code:
<?php
define('EMOTICONS_PER_ROW', '5');
$emoticons = range(1, 42);

$count = 0;
echo '<table border="1">';
while ($emoticons) {
  echo '<tr>';
  $row = array_splice($emoticons, 0, EMOTICONS_PER_ROW);
  while (count($row) < EMOTICONS_PER_ROW) {
    $row[] = '&nbsp;';
  }
  foreach ($row as $v) {
    echo "<td>$v</td>";
  }
  echo '</tr>';
}
echo '</table>';
?>
Related topics
Karma/Reputation System
Help on point system
FTP Codes
Report button/Warning System/Deal with tide of crud
Help : Fedora Core 4 + Ubuntu
FTP error codes -- What they mean
Help making an AJAX messaging system
Login System help
Need Help Yet again :: Comment system, data from 3 tables !!
system analysis... pls help..
php home system help
how do you create a login field with html?
Download System Help
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.