Hi, I need a table with dynamic header for first row and the rest of rows is the price.

Example:http://www.adtravel.com.my/domestic/package/142-legoland-2d1n-johor-special

Any idea to develop in admin page as well as product page? I want to use WYSIWYG editor but my client do not know how to use it.(Because the table must have a little design like background color for first row).

Any idea?

Recommended Answers

All 5 Replies

Are the number of columns always the same? If yes, you can just do something like this:

<?php
    $header_name_one = // some user input captured through POST or GET
    $header_name_two = // some user input captured through POST or GET
?>

<table>
    <tr>
        <th><?php echo $header_name_one; ?></th>
        <th><?php echo $header_name_two; ?></th>
    </tr>
    <tr>
        // loop through data
    </tr>
</table>

The number of column is not same. Any solution?

You can also try one like this.

First create a function to generate the <th> items. The function can be as simple as this

function create_th($col_header_name){

    if(is_array($col_header_name)){

        return array(true,$col_header_name);
      }

  }

to generate the cols, you call the function like this. There is no limit on how many header cells you can create.

$tbl_cols = create_th(array('Hotel','Class','Single','Adult(RM)','CNB(RM)'));

    if($tbl_cols[0]){


    echo '<table>';
    echo '<tr>';
    foreach($tbl_cols[1] as $th){
        echo '<th>'. $th.'</th>';
    }

    echo '</tr>';
    echo '</table>';

    }

The output should be something like this

<table>
   <tr>
    <th>Hotel</th>
    <th>Class</th>
    <th>Single</th>
    <th>Adult(RM)</th>
    <th>CNB(RM)</th>
   </tr>
</table>

Why use function?
By using function, you can utilize filter_var_array PHP function to filter the items going into the <th>.

that's it..

if you will be adding values for each column, then a second argument to the function must be added and make sure that the count of the values going underneath are perfectly equal to the number of <th> you need to create.

something like this

 create_th($cols_count, $col_header_name){

  if($cols_count > 0 && (is_array($col_header_name) && (count($col_header_name == $cols_count)))){

         return array(true,$col_header_name);
    }
}

Okay. I get your idea now. Thank you very much. =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.