Welcome Guest, Not a member yet? Register   Sign In
generate HTML table with variable number of columns and rows
#1

[eluser]Brain Coder[/eluser]
hello every one

i have a problem here in the viewer

i want to display result of the sql query and using it in html table

this is my view

Code:
if($category['cat_active'] == 'active'){
  if (count($subcat)){
    echo "الاقسام الفرعية";
    echo "<table id='cattable' align='center' cellspacing='0' cellpadding='3' width='50%' name='cattable'>\n";
    echo "<tr valign='top'>\n";
        foreach ($subcat as $key => $list){

            echo "<td align=center  style='font-family:Arial ;'>";
            echo anchor("smylat/category/$list[cat_id]","$list[cat_name]")   ;
            echo "</td>";

    }
    echo "</tr>";
    echo "</table>";
   }
echo "<br />";

i want to make in each row 4 td

i got this lesson and trying to make it work with me but its isnt

http://www.toppa.com/2008/generating-htm...-and-rows/

have any one an idea about this ?
#2

[eluser]jedd[/eluser]
Hi Brain,

What is the format of this $subcat variable that you refer:
Code:
if (count($subcat)){
It sounds like it's an array, or rather an array of arrays.

Rather than this:
Code:
echo anchor("smylat/category/$list[cat_id]","$list[cat_name]")   ;
I'd suggest this - mostly for readability, but it also stops you breaking things based on the different rules for quoting with single and double quotes.
Code:
echo anchor("smylat/category/". $list[cat_id] , $list[cat_name])   ;

And finally, to help us help you, tell us not only what output you expect, but also what you're actually getting. This is more useful than saying 'it doesn't work'.
#3

[eluser]Brain Coder[/eluser]
Welcome Jedd

The variable $subcat is an array of the category that have a root category

and the controller function is

Code:
function category($id = 0){
   $cat = $this->MCat->getCategory($id);
if (!count($cat)){
        redirect('smylat/index','refresh');
}
    $data['sets'] = $this->MSet->getAllSettings();
    $smylat = $this->MSmiles->getSmilesByCategory($id);
    $data['smylat'] = $smylat;
    $data['title'] = "سمايلات | " . $cat['cat_name']  ;
    $data['category'] = $cat;
    $data['subcat']= $this->MCat->getSubCategories($id);
    $data['main'] = 'category';
    $data['navigation'] = $this->MCat->getCategoriesNav();
    $this->load->vars($data);
    $this->load->view('smylat_template');
    //$this->output->enable_profiler(TRUE);
}

the problem in the veiw is
"when the subcat more than 6 or 7 or 8 subcat the table isnt splited "

i want to split the the td by the row

this is a pic for what i want
http://www.9amem.com/pics/1.gif

note that the viewer just view the first index of array "first sub category"


and this pic for what i have in viewer
http://www.9amem.com/pics/2.gif
#4

[eluser]jedd[/eluser]
So you just want to force a new row (TR) or even just a linebreak (BR), is that right?

Can you do something like this (or am I way off the mark?)

Code:
$i = 0;
        foreach ($subcat as $key => $list){
            echo "<td align=center  style='font-family:Arial ;'>";
            echo anchor("smylat/category/$list[cat_id]","$list[cat_name]")   ;
            echo "</td>";
            if ($i++ == 4)  {
                $i = 0;
                echo "</tr><tr>";   // Or a <br /> if that's all you need here.
                }
            }
#5

[eluser]Brain Coder[/eluser]
I love you man its work

thank you very much Smile

i will do the same thing when i want to show the images under the category

and using this library of pagenation
http://codeigniter.com/wiki/AJAX_Paginat...n_Library/

is it good ?
#6

[eluser]jedd[/eluser]
Quote:http://codeigniter.com/wiki/AJAX_Paginat...n_Library/

is it good ?

It is good.

Now, with that code - glad it's what you were after - but I suggest that you don't hard-code in the number 4 anywhere. Instead set it as an entry in your config.php file - it'll make it easier to change. You can then get funky with it (later) and assess how many entries across you want to show - based on the size of each entry (strlen() counts) or the size of the user's browser window (bit tricky - think you need JS for this) and so on.
#7

[eluser]Brain Coder[/eluser]
yes thats right

but in this time i just want to show 4 td in each tr

just take look here if the resolution was 800*600

http://www.9amem.com/pics/3.gif




Theme © iAndrew 2016 - Forum software by © MyBB