Jump to content

Archived

This topic is now archived and is closed to further replies.

almightyegg

I know this was posted the other day....

Recommended Posts

but i couldn't find the post :(

i have: $posmes[message] and i want to show say 4 or 5 words of it then ...
so if it was:
Hi guys, what you been doing?
it would show:
Hi guys, what you...
and then have a link to the full message...how would i do this???
(sorry is that made no sense)

Share this post


Link to post
Share on other sites
Something like

[code]
<?php
$msg = 'Hi guys, what you been doing?';

$short = join(' ', array_slice (explode(' ', $msg), 0, 4));

echo $short.'... <a href="somepage.php?id=$msgid">more</a>'; 
?>
[/code]

Share this post


Link to post
Share on other sites
When i ran it it gave

[code]
Hi guys, what you... <a href="somepage.php?id=$msgid">more</a>
[/code]

Share this post


Link to post
Share on other sites
[code=php:0]
<?
$msg = 'Hi guys, what you been doing?';
//i can't do the above line as the message is held in $posmes[messages]
//how would i adapt it??

$short = join(' ', array_slice (explode(' ', $msg), 0, 4));

echo $short.'... <a href="somepage.php?id=$msgid">more</a>'; 
?>
[/code]

Share this post


Link to post
Share on other sites
[code]
<?php

$msg = $posmes['messages'];

$short = join(' ', array_slice (explode(' ', $msg), 0, 4));

echo $short.'... <a href="somepage.php?id=$msgid">more</a>'; 

?>
[/code]

Share this post


Link to post
Share on other sites
nope didnt work still...just shows .'... :-X
[code=php:0][code]
$short = join(' ', array_slice (explode(' ', $msg), 0, 4));

$grabposts = mysql_query("SELECT * FROM im WHERE toid ='{$mem['id']}' ORDER BY `time` DESC LIMIT 100");
while($posmes = mysql_fetch_array($grabposts)){
echo "<tr bgcolor=#222222><td>$posmes[from]</td><td><a href=http://www.lordoftheabyss.com/im/viewmessage.php?id=$posmes[id]>$short.'...</a></td><td>$posmes[time]</td></tr>";
}
?>[/code][/code]

Share this post


Link to post
Share on other sites
you can create short message before you know whole message
move '$short = join(' ', array_slice (explode(' ', $posmes['message']), 0, 4));' in while loop (before echo)

Share this post


Link to post
Share on other sites
[quote author=almightyegg link=topic=112705.msg457631#msg457631 date=1161809059]
nope didnt work still...just shows .'... :-X
[code=php:0][code]
[/code][/code]
[/quote]

i think you may be taking the examples a little too literally and just plonking the code into yours and hoping for the best. as it stands at the moment, you have your $short = join(...etc line out on a limb, when i'm guessing that you want it to trim every message (as indicated by your first post in this thread). try this. i've also changed some of it to make it clearer/easier to read. IMO, embedding tonnes of HTML into a PHP string in a single 'echo' is a bad idea, especially with tables - makes it bloody hard to find issues or reorganise your layout in the future:

[code]
<?php
$grabposts = mysql_query("SELECT * FROM im WHERE toid ='{$mem['id']}' ORDER BY `time` DESC LIMIT 100");

while($posmes = mysql_fetch_array($grabposts))
{
  $short = join(' ', array_slice (explode(' ', $postmes['message']), 0, 4));
  ?>
  <tr bgcolor="#222222">
     <td>
        <?php echo $posmes['from']; ?>
     </td>
     <td>
        <a href="http://www.lordoftheabyss.com/im/viewmessage.php?id=<?php echo $posmes['id']; ?>"><?php echo $short; ?>...</a>
     </td>
     <td>
        <?php echo $posmes[time]; ?>
     </td>
  </tr>
<?php
}
?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.