0

i need a piece of code to break down the data brought in from the MYSQL database
im creating a small forum type on my website but with my layout if the user writes 5 lines it shows it all on 1 line and shows the bottom scroll bar,

i under stand that there is a for statement that will do it but unable to think of what the code is can any 1 help me out on this, thank you

2
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by nats01282
0
//database connection stuff
while($info = mysql_fetch_array($information))
{
 echo $info[message]."<br>";
}

this is all i got how would i split the array $info[message] and put a <br> every 5 words or so?

0

First of all I don't think that $info is an array.
You could use explode() based on " " (space) to turn it into an array. Then using a loop and counter turn it into a 5 word repeating block:

//I assume you are after a single record - so no while loop: 
$info = mysql_fetch_array($information);
//you could check to see if record exists with mysql_num_rows()
$input = $info['message'];
$input = str_replace("  "," ", $input); //this changes double spaces to single
$str = "";$counter = 0;
$parts = explode(" ", $info['message']);
foreach($parts as $part){
 if($counter == 5)$counter = 0;
 $str .= " " . $part;
 if($counter == 4)$str .= "<br />";
 $counter++;
}
$str = trim($str);

I bet there's a really nifty way to do this in a few lines, but I can't think of it.

Edited by diafol: n/a

0

Thank you ardav that solved my problem and yes it was needed in a while loop as i was extracting loads of info about the database but managed to work around the code

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.