almightyegg Posted October 25, 2006 Share Posted October 25, 2006 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 More sharing options...
Barand Posted October 25, 2006 Share Posted October 25, 2006 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] Link to comment https://forums.phpfreaks.com/topic/25089-i-know-this-was-posted-the-other-day/#findComment-114410 Share on other sites More sharing options...
almightyegg Posted October 25, 2006 Author Share Posted October 25, 2006 didn't work...it didnt even show the message..:( Link to comment https://forums.phpfreaks.com/topic/25089-i-know-this-was-posted-the-other-day/#findComment-114418 Share on other sites More sharing options...
Barand Posted October 25, 2006 Share Posted October 25, 2006 When i ran it it gave[code]Hi guys, what you... <a href="somepage.php?id=$msgid">more</a> [/code] Link to comment https://forums.phpfreaks.com/topic/25089-i-know-this-was-posted-the-other-day/#findComment-114422 Share on other sites More sharing options...
almightyegg Posted October 25, 2006 Author Share Posted October 25, 2006 [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] Link to comment https://forums.phpfreaks.com/topic/25089-i-know-this-was-posted-the-other-day/#findComment-114426 Share on other sites More sharing options...
alpine Posted October 25, 2006 Share Posted October 25, 2006 [code]<?php$msg = $posmes['messages'];$short = join(' ', array_slice (explode(' ', $msg), 0, 4));echo $short.'... <a href="somepage.php?id=$msgid">more</a>'; ?>[/code] Link to comment https://forums.phpfreaks.com/topic/25089-i-know-this-was-posted-the-other-day/#findComment-114433 Share on other sites More sharing options...
almightyegg Posted October 25, 2006 Author Share Posted October 25, 2006 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] Link to comment https://forums.phpfreaks.com/topic/25089-i-know-this-was-posted-the-other-day/#findComment-114441 Share on other sites More sharing options...
sasa Posted October 25, 2006 Share Posted October 25, 2006 you can create short message before you know whole messagemove '$short = join(' ', array_slice (explode(' ', $posmes['message']), 0, 4));' in while loop (before echo) Link to comment https://forums.phpfreaks.com/topic/25089-i-know-this-was-posted-the-other-day/#findComment-114445 Share on other sites More sharing options...
redbullmarky Posted October 25, 2006 Share Posted October 25, 2006 [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] Link to comment https://forums.phpfreaks.com/topic/25089-i-know-this-was-posted-the-other-day/#findComment-114446 Share on other sites More sharing options...
almightyegg Posted October 25, 2006 Author Share Posted October 25, 2006 it worked now...thanks all :) Link to comment https://forums.phpfreaks.com/topic/25089-i-know-this-was-posted-the-other-day/#findComment-114447 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.