News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Limited characters will appear and not whole last message?

Started by Realinfo, April 14, 2014, 12:17:07 PM

Previous topic - Next topic

Realinfo

By below code we can get last message of any particular Topic,

My issue is what changes is needed to make in below code so just 300 characters will appear and not whole last message

please guide changes in code

2.0.7 Default theme

global $smcFunc, $scripturl;

// Topic ID
$topic = XXXX;

$request = $smcFunc['db_query']('', '
SELECT t.id_topic, m.subject, m.body
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
WHERE t.id_topic = {int:topic}
LIMIT 1',
array(
'topic' => $topic,
)
);
list($id_topic, $subject, $body) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

$body = parse_bbc($body);

echo '
<strong><a href="', $scripturl, '?topic=', $id_topic, '.0">', $subject, '</a></strong>
<p>', $body, '</p>';

margarett

By uncle Google :P
http://stackoverflow.com/questions/3161816/php-cut-a-string-after-x-characters
There is even a function to prevent words to be cut

Or a search by: "php trim string to number of characters"
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Realinfo

I'm not that expert

please change above code and give to me,

margarett

Since you ask so nicely :P

global $smcFunc, $scripturl;

// Topic ID
$topic = XXXX;

$request = $smcFunc['db_query']('', '
SELECT t.id_topic, m.subject, m.body
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
WHERE t.id_topic = {int:topic}
LIMIT 1',
array(
'topic' => $topic,
)
);
list($id_topic, $subject, $body) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

$body = parse_bbc($body);
$body = (strlen($body) > 300) ? substr($body,0,297).'...' : $body;
echo '
<strong><a href="', $scripturl, '?topic=', $id_topic, '.0">', $subject, '</a></strong>
<p>', $body, '</p>';
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair


Kindred

Margarett -- for future reference, this user has removed the SMF and portal copyright.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

margarett

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Advertisement: