work_it_work Posted September 16, 2009 Share Posted September 16, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/174522-solved-need-help-foreach/ Share on other sites More sharing options...
work_it_work Posted September 17, 2009 Author Share Posted September 17, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/174522-solved-need-help-foreach/#findComment-919822 Share on other sites More sharing options...
work_it_work Posted September 17, 2009 Author Share Posted September 17, 2009 no one? :'( Quote Link to comment https://forums.phpfreaks.com/topic/174522-solved-need-help-foreach/#findComment-919995 Share on other sites More sharing options...
Zane Posted September 17, 2009 Share Posted September 17, 2009 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; } Quote Link to comment https://forums.phpfreaks.com/topic/174522-solved-need-help-foreach/#findComment-920123 Share on other sites More sharing options...
kickstart Posted September 17, 2009 Share Posted September 17, 2009 Hi Just had a play and tried that. Interesting and I like it. I need more CSS practice. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/174522-solved-need-help-foreach/#findComment-920130 Share on other sites More sharing options...
work_it_work Posted September 17, 2009 Author Share Posted September 17, 2009 thanks for your help i didn't try the css solution because i've solved the problem it's as simple as adding another foreach function and a column script foreach ($o as $opt) thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/174522-solved-need-help-foreach/#findComment-920359 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.