Jump to content

[SOLVED] need help foreach


work_it_work

Recommended Posts

here is the code i have. it works perfectly. the only problem is with the display...

foreach($options as $ids){
$o[]= show_option($ids);
}
$opt = implode("<br>", $o); 
echo $opt;

as it is, it's displaying only 1 column with all the rows.

 

what i want is to split that column it in 3 or 4 smaller columns ....

 

waiting for your suggestions

thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/174522-solved-need-help-foreach/
Share on other sites

here is the complete script and story:

 

this is the show_option function which pull out the name of the options from databese options table:

function show_option($id){
  $sql = "SELECT `value` FROM `options` WHERE `option_id` = '$id'";
  $res = mysql_query($sql) or die(mysql_error());
  $r = mysql_fetch_assoc($res);
  $input = $r['value'];
return $input;
}

This is the script that pull out the id's of the options from database and pass them to the function:

<?
$id_test = 35;

$sql = "SELECT options FROM listings WHERE list_id = '$id_test'";

$res = mysql_query($sql) or die(mysql_error());
$lcount = mysql_num_rows($res);
$r = mysql_fetch_assoc($res);
$options = explode(",", $r['options']);
// get names of options
foreach($options as $ids){
$o[]= show_option($ids);
}
$opt = implode("<br>", $o); 
echo $opt;
?>

 

The thing if it used like this it works and displays me the options list like this:

something

something

some text

another text

third text

.

.

.

last text

all this in one column...

 

if i replace the </br> with a comma , it will be something like this: something, something, some text, another text, third text, .... , last text.

 

what i want to obtain is 3 or 4 smallest columns instead of 1 big column, or enumeration

 

Waiting for suggestions

Thanks in advance!

Something like this

 

$opt = implode("

  • ", $o);

    echo "

      ";

      echo "

    • " . $opt . "
    • ";

      echo "

    ";

     

    The CSS:
    ul {
      float: left;
      width: 12em;
      margin: 0;
      padding: 0;
      list-style: none;
    }
    
    li {
      float: left;
      width: 6em;
      margin: 0;
      padding: 0;
    }
    

  • Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.