How can I post smileys in a comment form? php/mySQL comments
Posted: Tue Dec 02, 2008 10:28 am
Its a php mySQL comment system. Im a bit of a php noob too so go easy on me. :D
I want to post smileys like this :) or :D and have them show up as smiley gifs, how would I make the php recognize the anscii smiley and then post its image? I think there needs to be some altering to the mySQL table since flag varchar(20) NOT NULL default '', and rating tinyint(1) NOT NULL default '0', sound like they may have something to do with the flag.png files and the Rating.png files. Heres a link to an example of how the comment system looks and works http://www.plentyoftorrents.com/flsh/an ... c.php#post (scroll up to see comments)
Thanks for any help.
Here is the mySQL table thing I had to import into phpmyadmin when installing the script.
Heres the comments show php page that contains the rating and flag images, so Im assuming thats where any smileys will have to go.
I want to post smileys like this :) or :D and have them show up as smiley gifs, how would I make the php recognize the anscii smiley and then post its image? I think there needs to be some altering to the mySQL table since flag varchar(20) NOT NULL default '', and rating tinyint(1) NOT NULL default '0', sound like they may have something to do with the flag.png files and the Rating.png files. Heres a link to an example of how the comment system looks and works http://www.plentyoftorrents.com/flsh/an ... c.php#post (scroll up to see comments)
Thanks for any help.
Here is the mySQL table thing I had to import into phpmyadmin when installing the script.
Code: Select all
#
# Table structure for table `page_comments`
#
CREATE TABLE IF NOT EXISTS page_comments (
id mediumint(11) NOT NULL auto_increment,
name varchar(40) NOT NULL default '',
location varchar(40) NOT NULL default '',
flag varchar(20) NOT NULL default '',
comments text NOT NULL,
ip varchar(20) NOT NULL default '',
page_id varchar(40) NOT NULL default '0',
dated datetime NOT NULL default '0000-00-00 00:00:00',
rating tinyint(1) NOT NULL default '0',
admin_comment text NOT NULL default '',
is_approved tinyint(1) NOT NULL default '1',
PRIMARY KEY (id)
) TYPE=MyISAM AUTO_INCREMENT=1 ;Code: Select all
<?php
/***********************************************************************************
There is no need to edit ANYTHING below this comment. Almost EVERYTHING you need
to edit is contained in the comments-config.php file and comments-lang.php file.
PLEASE READ THE DOCUMENTATION FILE!
************************************************************************************/
include("includes/comments-config.php"); // configuration parameters package
include("includes/comments-lang.php"); // language/words package
$comm_page = is_numeric($_GET['comm_page']) ? $_GET['comm_page'] : 1;
if ($comm_page<1) {
$comm_page = 1;
}
// Figure out the limit for the query based on the current page number.
$from = $comm_page * $comment_limit - $comment_limit;
include("includes/db_conn.php"); // connect to host and select db
mysql_connect($db_host, $db_user, $db_pass) or die("Connection Error: ". mysql_error());
mysql_select_db($db_name);
// construct page query to find out how many matches
$result=mysql_db_query($db_name,"select count(*) from $db_table WHERE page_id='$page_id' AND is_approved = '1'");
$count=mysql_result($result,0,"count(*)");
$total_pages = ceil($count / $comment_limit);
// and the average rating is ...
$query = "SELECT AVG(rating) from $db_table WHERE page_id='$page_id' AND is_approved = '1' AND rating>'0'";
$result = mysql_query($query) or die("error ". mysql_error(). " with query ".$query);
$row = mysql_fetch_array($result);
$av_rating = number_format($row['AVG(rating)'],2);
// construct page query to find out how many matches
$query = "SELECT * from $db_table WHERE page_id = '$page_id' AND is_approved = '1' ORDER by dated DESC LIMIT $from, $comment_limit";// what matches THIS page?
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
// skip output if no comments exist
if (!$count) {
echo "<p style='". $num_style. "'>". $no_comments. "</p>";
} else {
echo "<p style='". $num_style. "'>". $comments_to_date. $count. $this_is_page. $comm_page. $page_of_page. $total_pages. ". ";
if (($av_rating>0) && ($art_rating==1)) {
$stars = 5 * round($av_rating/0.5);
echo $average_rating. "<img src='comments/images/stars/stars_". $stars. ".png' alt=''/>";
}
echo "</p>";
// output comments
echo "<table cellpadding='0' cellspacing='0' width='100%' border='0' align='center'>";
while ($myrow = mysql_fetch_array($result)) // loop through all results
{
$style = $style == $ro1 ? $ro2 : $ro1;
echo "<tr bgcolor='". $style. "'>";
echo "<td><p style='". $comm_style. "'><b>";
if ($show_flags == 1) {
$flag_image = "comments/images/flags/". $myrow['flag']. ".png";
if (file_exists($flag_image)) {
$size = getimagesize($flag_image);
echo " <img src='". $flag_image. "' ". $size[3]. " alt=''/> ";
}
if (!$myrow['name']) {
echo $unknown_poster;
} else {
echo $myrow['name'];
}
}
echo "</b></p></td>";
echo "<td align='right'><p style='". $commdate_style. "'>";
niceday($myrow['dated']);
echo "<br/>";
if (($art_rating==1) && ($myrow['rating']>0) && ($visitor_rating==1)) {
$star_img = "comments/images/stars/stars_". 10*$myrow['rating']. ".png";
$size = getimagesize($star_img);
echo " <img src='". $star_img. "' ". $size[3]. " alt=''/>";
}
echo "</p></td></tr>";
echo "<tr bgcolor='". $style. "'>";
echo "<td colspan='2' style='border-bottom:1px dotted ". $space_color. ";'><p style='". $comm_style. "'>";
$comments = stripslashes($myrow['comments']);
if (strlen($comments)>$maxshow_comments) {
$comments = substr($comments,0,$maxshow_comments). "... <a href='comments/showmore.php?id=". $myrow['id']. "'>". $show_more. "</a> <strong>»</strong>";
}
echo nl2br($comments);
if ($myrow['admin_comment']) {
echo "<br/><br/>". $admin_comment. " <span style='color:#c30;'><em>". $myrow['admin_comment']. "</span></em>";
}
echo "</p></td></tr>\n";
}
// loop done
echo "</table>\n";
}
// Pagination magic (of sorts)
if ($total_pages>1) {
echo "<p><br/>Page: ";
for ($z=-5; $z<6;$z++) {
$dapage = $comm_page+$z;
if (($dapage>0) && ($dapage<=$total_pages)) {
if ($dapage==$comm_page) {
echo "-". $dapage. "-";
} else {
echo "<a class='pagelink' href='". $_SERVER['PHP_SELF']. "?comm_page=". $dapage. "'> ". $dapage. " </a>";
}
echo " ";
}
}
echo "</p>";
}
?>