[SOLVED] string manipulation question
Posted: Wed Jan 03, 2007 3:45 pm
i'm populating a bulleted list of categories from a MySQL table. simple stuff. however, this list is going to be on the left side of a table column. like a navigation menu on the left of a website. the problem is, if the name in the database that's populating the bulleted list is too long, it extends into the rest of the website. i want to incorporate a script in my while loop, so that if the string name is over whatever characters long, go back to the 20th character, and grab the whitespace to the left of it, then skip a line.
for example, i want this...
to become this:
here's my code now...
$row['name'] is the string being manipulated. where would i start? i'm sure there's many ways to skin this cat, which method(s) should i use and why?
thanks for all your help.
for example, i want this...
Code: Select all
+--------------+
| Categories |
+--------------+
| 1. Plates |
| 2. Spoons |
| 3. Forks |
| 4. Knives |
| 5. Pressure Cookers |
| 6. Bed Sheets|
| 7. Pots and Pans |
| 8. Wine |
| 9. Salt and Pepper |
+--------------+Code: Select all
+--------------+
| Categories |
+--------------+
| 1. Plates |
| 2. Spoons |
| 3. Forks |
| 4. Knives |
| 5. Pressure |
| Cookers |
| 6. Bed Sheets|
| 7. Pots and |
| Pans |
| 8. Wine |
| 9. Salt and |
| Pepper |
+--------------+Code: Select all
<UL>
<?php
$sql = mysql_query("SELECT * FROM categories WHERE parent=0");
while($row = mysql_fetch_array($sql)){
echo "<LI><a href=\"index.php?cat=". $row[id] ."\">". $row[name] ."</a></LI>\n";
}
?>
</UL>thanks for all your help.