Jump to content


Photo

help with a function...


  • Please log in to reply
1 reply to this topic

#1 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 26 October 2006 - 11:18 AM

i have a function to add smileysthat works fine on my message board, but not on my updates!
[code]
<?
function emoticon($post) {
   $emoticonarray = array(
      ':)'  => 'smile.gif',
      ':('  => 'sad.gif',
      ';)'  => 'wink.gif',
      ':P'  => 'tongue.gif',
      ':D'  => 'cheese.gif'
   );

   foreach($emoticonarray as $emoticon => $img) {
      $search[] = $emoticon;
      $replace[] = '<img src="http://lordoftheabyss.com/images/emotions/' . $img . '" alt="' . $emoticon . '" />';
   }
   $post = str_replace($search, $replace, $post);
   return $post;
}
$post = emoticon($updates[uptext]);

$datessql = mysql_query("SELECT * FROM updates order by time desc LIMIT 10");
while($updates = mysql_fetch_array($datessql)){



echo "<tr><td width=150 bgcolor=#101010>$updates[time]</tD><td width=550 bgcolor=#222222><left><b>$updates[title]</b></left></td></tr><tr><td bgcolor=#222222>Posted By:<br><a href=http://www.lordoftheabyss.com/player/view.php?id=$updates[id]>$updates[username]</a></td><td bgcolor=#101010>emoticon($updates[uptext])</td></tr>";
}
?>[/code]

Visit my Game - Under Construction

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 26 October 2006 - 11:24 AM

Move
$post = emoticon($updates[uptext]);
inside the where loop first.

Then change this:
<td bgcolor=#101010>emoticon($updates[uptext])</td>

To this:
<td bgcolor=#101010>$post</td>

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users