Jump to content

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;
    }
    

  • This thread is more than a year old. Please don't revive it unless you have something important to add.

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Restore formatting

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • 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.