Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating automatic bulleted single line breaks from one mysql field

Status
Not open for further replies.

tshey

Technical User
Dec 28, 2005
78
AU
I have a item_desc field within my items table. Can I enter a description but make each line automatically go to the next line and add a bullet in front of each line of text.
<?php echo $row_items["itemDesc"]; ?>
 
You could enter sufficient HTML into the description field that the output would do all that. But I strongly recommend against it.

I think you will have much greater flexibility storing only data in the database and using PHP to wrap formatting around it. If you need to change the formatting and you do the formatting in PHP, then you only have to change the PHP script. If you store the formatting with the data in the field, you'll have to perform a complex update on every record in the table to make a formatting change.

You could even develop some kind for templating system, where your PHP script retrieves the data from your items table, a template from your template table, then combine the two. Although this is slightly more complex than storing templates in PHP code, it's not a lot more complex. And you if need to change the formatting, you only need to change one record in one table.



Want the best answers? Ask the best questions! TANSTAAFL!
 
function genList($passedArray = 404, $optListType="unordered list", ... more things here) {
//your code here
if ($passedArray != 404) {
$theList = $listType[$optListType];
while ($i = 0; $i < count($passedArray); $i++) {

}
}
else
{
$theList = "<ul><li>Missing</li></ul>";
}
return $theList;
}

Pass the array to the genList() (which you have to program), make it pass back the entire list.

I would make the genList accept a couple of variables, though most of them optional (defaulting to values).

like: bullet type, psuedoclass, list-type, etc.
(ordered list, unordered list)

ps. the example might be buggy, I havent touched php in a while (doing mostly asp.net now). Take it as psuedocode, as it's not tested.

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top