Jump to content


Photo

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


  • Please log in to reply
9 replies to this topic

#1 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 25 October 2006 - 07:12 PM

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)
Visit my Game - Under Construction

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 25 October 2006 - 07:50 PM

Something like

<?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>';  
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 25 October 2006 - 07:58 PM

didn't work...it didnt even show the message..:(
Visit my Game - Under Construction

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 25 October 2006 - 08:03 PM

When i ran it it gave

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

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 25 October 2006 - 08:10 PM

<?
$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>';  
?>

Visit my Game - Under Construction

#6 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 25 October 2006 - 08:21 PM

<?php

$msg = $posmes['messages'];

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

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

?>


#7 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 25 October 2006 - 08:44 PM

nope didnt work still...just shows .'... :-X
[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]

Visit my Game - Under Construction

#8 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 25 October 2006 - 08:54 PM

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)

#9 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 25 October 2006 - 08:56 PM

nope didnt work still...just shows .'... :-X

[code]
[/code]


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:

<?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
}
?>

"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#10 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 25 October 2006 - 08:57 PM

it worked now...thanks all :)
Visit my Game - Under Construction




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users