Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks
Author Message
mcoupa
New Member
New Member



Joined: Dec 02, 2004
Posts: 12

PostPosted: Sun Jan 23, 2005 6:49 am Reply with quote

Hi

I need some help to change this code so that it limits the title to e.g. 16 characters.

what happens currently is that if someone posts a message with no spaces in the title like:
adkfljasdkfjlkasdjfklajsdlkfjklasdjfljasdlkfjlasdk
the block width is messed up and it messes up the whole site.

here's the code for the block:
Code:



<?php

if (eregi("block-Forums.php", $_SERVER['PHP_SELF'])) {
    Header("Location: index.php");
    die();
}

global $prefix, $db, $sitename;

$result = $db->sql_query("SELECT forum_id, topic_id, topic_title FROM ".$prefix."_bbtopics ORDER BY topic_time DESC LIMIT 10");
$content = "<br>";
while ($row = $db->sql_fetchrow($result)) {
    $forum_id = intval($row['forum_id']);
    $topic_id = intval($row['topic_id']);
    $topic_title = $row['topic_title'];
    $row2 = $db->sql_fetchrow($db->sql_query("SELECT auth_view, auth_read FROM ".$prefix."_bbforums WHERE forum_id='$forum_id'"));
    $auth_view = intval($row2['auth_view']);
    $auth_read = intval($row2['auth_read']);
    if (($auth_view < 2) OR ($auth_read < 2)) {
        $content .= "<a href=\"forums.html?amp;file=viewtopic&amp;t=$topic_id\">$topic_title</a><br>";
    }
}

$content .= "<br><center><a href=\"forums.html\"><b>$sitename Forums</b></a><br><br></center>";

?>

how do I truncate the title?
 
View user's profile Send private message
hitwalker
Sells PC To Pay For Divorce



Joined:
Posts: 5661

PostPosted: Sun Jan 23, 2005 7:45 am Reply with quote

Hi this is a sample of how the stripping works.....
sample is from my downloads block...
you can play with it and duplicate it.....

Code:


$content .= "";
global $prefix, $dbi;
$strip = "15";
$linkstrip1 = stripslashes($title);
$linkstrip2 = substr($linkstrip1, 0, $strip) . "..";
$title2 = ereg_replace("_", " ", $title);
$content .= "<a href=\"modules.php?name=Downloads&amp;op=getit&amp;lid=$lid\">$linkstrip2</a><br>";
    $a++;
}
 
View user's profile Send private message
mcoupa







PostPosted: Sun Jan 23, 2005 7:52 am Reply with quote

thanks
although I'm not a hardcore coder, is it not better to use LIMIT 0,15 somewhere?
 
hitwalker







PostPosted: Sun Jan 23, 2005 7:57 am Reply with quote

well me neither but of what ive seen the limit is usualy used in sql query.
the posted code is exactly your situation...and you have to play with it.
this can be simple...
 
mcoupa







PostPosted: Sun Jan 23, 2005 8:21 am Reply with quote

I figured it out. here's the code:
Code:


<?php

if (eregi("block-Forums.php", $_SERVER['PHP_SELF'])) {
    Header("Location: index.php");
    die();
}

global $prefix, $db, $sitename;

$result = $db->sql_query("SELECT forum_id, topic_id, topic_title FROM ".$prefix."_bbtopics ORDER

BY topic_time DESC LIMIT 15");
$content = "<br>";
while ($row = $db->sql_fetchrow($result)) {
    $forum_id = intval($row['forum_id']);
    $topic_id = intval($row['topic_id']);
    $topic_title = $row['topic_title'];
    $title1 = substr("$topic_title", 0,18);
    $row2 = $db->sql_fetchrow($db->sql_query("SELECT auth_view, auth_read FROM

".$prefix."_bbforums WHERE forum_id='$forum_id'"));
    $auth_view = intval($row2['auth_view']);
    $auth_read = intval($row2['auth_read']);
    if (($auth_view < 2) OR ($auth_read < 2)) {
        $content .= "<a

href=\"modules.php?name=Forums&amp;file=viewtopic&amp;t=$topic_id\">$title1...</a><br>";
    }
}



?>
 
hitwalker







PostPosted: Sun Jan 23, 2005 8:22 am Reply with quote

well good for you.....you knew it al along...
 
mcoupa







PostPosted: Sun Jan 23, 2005 8:26 am Reply with quote

ya I was too lazy it's a sunday...

i was looking for an easy way out Smile
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©