Jump to content

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)
Link to comment
https://forums.phpfreaks.com/topic/25089-i-know-this-was-posted-the-other-day/
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]
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]
[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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.