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

Member Avatar for diafol

Show YOUR code first to see where you've got to.

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

Member Avatar for diafol

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.

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

Member Avatar for diafol

Ok we solved?

yep thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.