Jump to content


Photo

Separate a string into a list with PHP


  • Please log in to reply
1 reply to this topic

#1 centenial

centenial
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 10 June 2006 - 04:52 PM

Hi,

I have a field in a database table named "features". It has a value of:

feature1,feature2,feature3,feature4,feature5 (and so on)

I want to display the features in a bulleted list, like this:

<li>feature1</li>
<li>feature2</li>
<li>feature3</li>
<li>feature4</li>
<li>feature5</li>
(And so on)

Is there a way I can do this with PHP & Arrays? Can anyone show me a code example?

Thanks!

#2 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 10 June 2006 - 04:57 PM

$sql = "SELECT * FROM `features` ORDER BY `id` ASC";
$result = mysql_query ($sql) or die (mysql_error());
while ($feature = mysql_fetch_array ($result))
{
  ?><li><?=$feature['feature_name']?></li><?
}

my mistake

$db_feature is the field lets say

<?
$features = explode (",", $db_feature);
foreach ($features as $feature)
{
?><li><?=$feature?></li><?
}
?>

z..z..z..z..z..z..z..z..




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users