PHPNewbie
PHPNewbie

Reputation: 35

PHP MYSQL Word Wrap

I am new on PHP, i am wondering where can i insert / use the wordwrap code in my existing code. My objective is to apply word wrap to the Brand description data: Below are the details:

This is a part of my existing code that displays the data from MYSQL into an HTML table:

$data = mysql_query("SELECT * from web_brands");
//Display table headers
print ("<table border='1' ALIGN = 'CENTER' 
width='800'><tr><th>ID</th><th>LOGO</th><th>BRANDNAME</th><th>DESCRIPTION</th><th>SHORTNAME    </th></tr>");

while($row = mysql_fetch_array($data)){   //Display the results in different cells  
echo "<tr>";
echo '<td>' .$row['brand_id'] . '</td>';
echo "<td>" . "<img width=300px height=200px src=../brandslogo/" . $row  ['logo'].">" . "</td>";
echo "<td>" . $row['brand_name'] . "</td>";
echo '<td width="300">' . $row['brand_description']  . "</td>";
echo "<td>" . $row['brand_shortname'] . "</td>";
echo "</tr>";
}

I want to apply a word wrap to the brand description field and i do not know how to do it. Hope you can help

Upvotes: 0

Views: 2468

Answers (1)

Pramendra Gupta
Pramendra Gupta

Reputation: 14873

use native function of

http://php.net/manual/en/function.wordwrap.php

//change this
echo "<td>" . $row['brand_name'] . "</td>";
//to , this will wrap for each 20 width
echo "<td>" . wordwrap($row['brand_description'], 20, "<br />\n") . "</td>";

Upvotes: 2

Related Questions