Code: Select all
<?php
$query = mysql_query("select * from articles where id = 4");
while ($out = mysql_fetch_array($query)) {
$thread_title=$outї"title"];
}
echo "{$thread_title}";
?>Any ideas?
Moderator: General Moderators
Code: Select all
<?php
$query = mysql_query("select * from articles where id = 4");
while ($out = mysql_fetch_array($query)) {
$thread_title=$outї"title"];
}
echo "{$thread_title}";
?>Code: Select all
<?php
//cut the string
$substring = substr($thread_title,0,11);
//adding the ...
echo $substring.'...';
?>Code: Select all
$truncated_text .= (strlen($truncated_text) == 20) ? '...' : '';Code: Select all
$truncated_text .= (strlen($truncated_text) == 20) ? '...' : '';Code: Select all
$truncated_text = (strlen($truncated_text) == 20) ? '...' : '';Code: Select all
<?php
$maxlength = 20;
if (strlen($thread_title) > $maxlength){
$truncatedtext = substr($thread_title, 0, $maxlength) . "...";
} else {
$truncatedtext = $thread_title;
}
?>It was an example which assumed that the truncated text had been set to a variable called $truncated_text - you already had the code for doing that so I didn't repeat it. In your code the truncated text was set to $thread_title.AliasBDI wrote:Doesn't work. It will not even display the text at all. I also tried this w/out the period in it:Code: Select all
$truncated_text .= (strlen($truncated_text) == 20) ? '...' : '';
Code: Select all
$truncated_text = (strlen($truncated_text) == 20) ? '...' : '';
Code: Select all
function do_lastposts() {
global $DB, $ibforums, $root_path, $templates_dir, $std, $INFO;
$admin_forums = '(0)'; // IDs of the Forums you want to hide;
$limit = "5"; // Number of posts to show
$prefix = $INFOї'sql_tbl_prefix'];
$template = load_template("lastposts.html");
$to_echo = "";
$DB->query( "SELECT p.pid, p.author_name, p.post_date, p.forum_id, p.topic_id, p.author_id, t.title ,f.name FROM ".$prefix."posts p , ".$prefix."topics t, ".$prefix."forums f WHERE t.tid=p.topic_id AND t.forum_id=f.id AND p.forum_id NOT IN ".$admin_forums." ORDER BY pid DESC LIMIT 0,".$limit." " );
if ( ! $DB->get_num_rows() )
{
fatal_error("Could not get the information from the database");
}
while( $out = $DB->fetch_row($query) ) {
$thread_title = $outї'title'];
$forum_name =$outї'name'];
$author = $outї'author_name'];
$outї'post_date'] = $std->get_date( $outї'post_date'], 'LONG' );
$date = $outї'post_date'];
$to_echo .= parse_template( $template,array (
'thread_url' => $ibforums->base_url."?act=ST&f=".$outї'forum_id']."&t=".$outї'topic_id']."&hl=&#entry".$outї'pid'],
'thread_title' => $thread_title,
'forum_url' => $ibforums->base_url."?act=SF&f=".$outї'forum_id'],
'forum_name' => $forum_name,
'date' => $date,
'author' => $author,
'profile_link' => $ibforums->base_url."?act=Profile&CODE=03&MID=".$outї'author_id'], ) );
}Code: Select all
t.titleCode: Select all
SUBSTRING(t.title, 0, 20) AS titleCode: Select all
$thread_title = $out['title'];Code: Select all
$thread_title = $out['title'];
if (strlen($thread_title) == 20) {
$thread_title .= '...';
}Yup, copied it out of your code because I always forget the order of stuff for the substring() functions and figured you'd probably looked it up when you posted... I've corrected the code above.pootergeist wrote:betcha posted the substring() mysql code after reading my post huh?
that should be
SUBSTRING(t.title,0,20) AS title,
note the 0,
Code: Select all
function do_lastposts() {
global $DB, $ibforums, $root_path, $templates_dir, $std, $INFO;
$admin_forums = '(0)'; // IDs of the Forums you want to hide;
$limit = "5"; // Number of posts to show
$prefix = $INFOї'sql_tbl_prefix'];
$template = load_template("lastposts.html");
$to_echo = "";
$DB->query( "SELECT p.pid, p.author_name, p.post_date, p.forum_id, p.topic_id, p.author_id, SUBSTRING(t.title,0,20) AS title, f.name FROM ".$prefix."posts p , ".$prefix."topics t, ".$prefix."forums f WHERE t.tid=p.topic_id AND t.forum_id=f.id AND p.forum_id NOT IN ".$admin_forums." ORDER BY pid DESC LIMIT 0,".$limit." " );
if ( ! $DB->get_num_rows() )
{
fatal_error("Could not get the information from the database");
}
while( $out = $DB->fetch_row($query) ) {
$thread_title = $outї'title'];
if (strlen($thread_title) == 20) {
$thread_title .= '...';
}
$maxlength = 20;
if (strlen($thread_title) > $maxlength){
$truncatedtext = substr($thread_title, 0, $maxlength) . "...";
} else {
$truncatedtext = $thread_title;
}
//$thread_title = (strlen($thread_title) == 20) ? '...' : '';
$forum_name = $outї'name'];
$author = $outї'author_name'];
$author = substr("$author", 0, 10);
$outї'post_date'] = $std->get_date( $outї'post_date'], '2DIGITS' );
$date = $outї'post_date'];
$to_echo .= parse_template( $template,array (
'thread_url' => $ibforums->base_url."?act=ST&f=".$outї'forum_id']."&t=".$outї'topic_id']."&hl=&#entry".$outї'pid'],
'thread_title' => $thread_title,
'forum_url' => $ibforums->base_url."?act=SF&f=".$outї'forum_id'],
'forum_name' => $forum_name,
'date' => $date,
'author' => $author,
'profile_link' => $ibforums->base_url."?act=Profile&CODE=03&MID=".$outї'author_id'], ) );
}