ryogun Posted June 5, 2009 Share Posted June 5, 2009 hello there, im new to these forums and also a newbie at php, and i saw this would be the best place to get help, i have a simple problem i hope, that i dont know how to fix since im not that knowledgeable on php i have a simple php script that takes out the most recent topics of my forum, the only problem is, when somebody makes one that it is too long, like for example "teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeest" would be too long and mess up my layout because it is on a table, is there a way like if the message is too long, it would be turned like this teeeeeee... and have a certain number of characters that would show up? example hello test test test would be hello test... help is appreciated php script bellow <?php // // Basic Configuration // How Many Topics you want to display? $topicnumber = 10; // Scrolling towards up or down? $scroll = "down"; // Change this to your phpBB path $urlPath = "************"; // Database Configuration (Where your phpBB config.php file is located include '**********'; // Connecting & Selecting Databases $table_topics = $table_prefix. "topics"; $table_forums = $table_prefix. "forums"; $table_posts = $table_prefix. "posts"; $table_users = $table_prefix. "users"; $link = mysql_connect("$dbhost", "$dbuser", "$dbpasswd") or die("Could not connect"); mysql_select_db("$dbname") or die("Could not select database"); // Perform Sql Query $query = "SELECT t.topic_id, t.topic_title, t.topic_last_post_id, t.forum_id, p.post_id, p.poster_id, p.post_time, u.user_id, u.username FROM $table_topics t, $table_forums f, $table_posts p, $table_users u WHERE t.topic_id = p.topic_id AND f.forum_id = t.forum_id AND t.topic_status <> 2 AND p.post_id = t.topic_last_post_id AND p.poster_id = u.user_id ORDER BY p.post_id DESC LIMIT $topicnumber"; $result = mysql_query($query) or die("Query failed"); // Outcome of the HTML // Be carefull when you edit these! print "<marquee id=\"recent_topics\" behavior=\"scroll\" direction=\"$scroll\" height=\"130\" scrolldelay=\"1\" scrollamount=\"2\" onMouseOver=\"document.all.recent_topics.stop()\" onMouseOut=\"document.all.recent_topics.start()\"> <table cellpadding='3' cellSpacing='2' width='50'>"; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<tr valign='top'><td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"><font color=\"#FFCC00\"><b><a href=\"$urlPath/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]\">" . $row["topic_title"] . "</a></td></font></b><td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"><font color=\"#C0C0C0\"> by: <a href=\"$urlPath/memberlist.php?mode=viewprofile&u=$row[user_id]\">" . $row["username"] . "</td><td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\"><font color=\"#C0C0C0\">" . date('F j, Y, g:i a', $row["post_time"]) . "</td></tr></font>"; } print "</table></marquee>"; // Free Result mysql_free_result($result); // Close the Connection mysql_close($link); ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 5, 2009 Share Posted June 5, 2009 You can do what you're after with a few of the string functions. E.g: strlen and substr_replace. In future, please try to wrap your code in tags. And welcome to the forums. Quote Link to comment Share on other sites More sharing options...
ryogun Posted June 6, 2009 Author Share Posted June 6, 2009 sorry about that, im really a n00b on php any idea how they would be implemented? or kind of used, ill try to find tutorial see if i can understand it somewhat, either way, thanks. Quote Link to comment Share on other sites More sharing options...
allistera Posted June 6, 2009 Share Posted June 6, 2009 http://www.meiocodigo.com/2008/10/14/pretty-truncate-string-function-in-php-substr-replacement/ Quote Link to comment Share on other sites More sharing options...
ryogun Posted June 6, 2009 Author Share Posted June 6, 2009 nevermind, found the problem, sorry for the bother, and thanks for the help! 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.