Hello, please sign in or register
You are here: Home

Creating html tables from a dataset

[CODE=function html_tables()] $v) { $s .= ' '.$k.'="'.$v.'"'; } } $s .=">"; if ( isset( $p['status'] ) ) { $caption_list .= "
  • " . ( $p['status']['selected'] === NULL ? "All" : "All" ) . "
  • "; foreach( $p['status']['list'] as $k => $v ) { $caption_list .= "
  • " . ( $p['status']['selected'] !== NULL && $p['status']['selected'] == $k ? $v : " $k) ) ) . "'>$v" ) . "
  • "; } } $s .= isset( $p['caption'] ) ? "" . $p['caption'] . ( isset ( $caption_list ) ? "
      " . $caption_list . "
    " : NULL ) . '' : ''; /************************ * Column title THEAD ************************/ if( !isset($p['column_titles']) && isset($p['data'][0]) ) { foreach( $p['data'][0] as $c => $v ) { $p['column_titles'][$c] = $c; } } if ( isset( $p['column_titles'] ) ) { $s .= ""; foreach( $p['column_titles'] as $k => $c ) { if ( isset( $p['asc-desc'][$k] ) ) { if ( $p['scroll']['gets']['desc'] != NULL && $p['scroll']['gets']['desc'] == $p['asc-desc'][$k] ) { $a = array('desc' => NULL); $a += array( 'asc' => $p['asc-desc'][$k] ); } else { $a = array('asc' => NULL); $a += array( 'desc' => $p['asc-desc'][$k] ); } $a = array_merge( ( is_array( $p['scroll']['gets'] ) ? $p['scroll']['gets'] : array() ) , $a ); $c = "" . $c . ""; } $s .= "$c"; } $s .= ""; } /** * Create Scroll navigation */ if ( isset( $p['scroll'] ) /* && ( $p['scroll']['found_rows'] > $p['scroll']['rows'] ) */ ) { $scroll = "
    Total " . $p['scroll']['found_rows'] . " | Displaying " . ( $p['scroll']['start'] + 1 ) . " to " . ( ( $tmp = $p['scroll']['start'] + $p['scroll']['rows'] ) > $p['scroll']['found_rows'] ? $p['scroll']['found_rows'] : $tmp ) . "
    "; $scroll .= "
    "; $scroll .= ( $p['scroll']['start'] > 0 ? " ( - $p['scroll']['rows'] + $p['scroll']['start'] )) ) ) . "'>prev" : "prev" ); $scroll .= " | "; $scroll .= ( $p['scroll']['found_rows'] > ( $p['scroll']['rows'] + $p['scroll']['start'] ) ? " ( $p['scroll']['rows'] + $p['scroll']['start'] ) ) ) ) . "'>next" : "next" ); $scroll .= "
    "; } /** * Summary information TFOOT * By W3 this has to be before TBODY */ if ( isset( $p['summary'] ) || isset( $scroll ) ) { $s .= ""; if ( isset( $p['summary'] ) ) { $s .= ""; foreach( $p['column_titles'] as $k => $c ) { if ( isset( $p['summary'][$k] ) ) { $s .= "" . $p['summary'][$k] . ""; } else { $s .= " "; } } $s .= ""; } if ( isset($scroll) ) { $s .= "" . $scroll . ""; } $s .= ""; } /** * Create Table Rows Attr */ if( ! isset( $p['tr_attr'][0], $p['tr_attr'][1] ) ) { $p['tr_attr'] = array('od', 'ev'); } /** * Create Rows */ $s .= ""; if($p['data'] == NULL) { $s .= "No Results"; } else { $i=0; foreach( $p['data'] as $r ) { $i = ($i>1) ? $i=0 : $i; $s .= ""; foreach($p['column_titles'] as $k => $c) { $s .= "". ( is_array( $r[$k] ) ? print_list($r[$k]) : $r[$k] ) .""; } $s .= ""; } } $s .= ""; $s .= ""; return $s; } ?> [/CODE] mark 2 [CODE=example.code] $v) { $s .= ' '.$k.'="'.$v.'"'; } $s .=">"; if ( isset( $p['status'] ) ) { $caption_list .= "
  • " . ( $p['status']['selected'] === NULL ? "All" : "All" ) . "
  • "; foreach( $p['status']['list'] as $k => $v ) { $caption_list .= "
  • " . ( $p['status']['selected'] !== NULL && $p['status']['selected'] == $k ? $v : " $k) ) ) . "'>$v" ) . "
  • "; } } $s .= isset( $p['caption'] ) ? "" . $p['caption'] . ( isset ( $caption_list ) ? "
      " . $caption_list . "
    " : NULL ) . '' : ''; /************************ * Column title THEAD ************************/ if( !isset($p['column_titles']) && isset($p['data'][0]) ) { foreach( $p['data'][0] as $c => $v ) { $p['column_titles'][$c] = $c; } } if ( isset( $p['column_titles'] ) ) { $s .= ""; foreach( $p['column_titles'] as $k => $c ) { if ( isset( $p['asc-desc'][$k] ) ) { if ( $p['scroll']['gets']['desc'] != NULL && $p['scroll']['gets']['desc'] == $p['asc-desc'][$k] ) { $a = array('desc' => NULL); $a += array( 'asc' => $p['asc-desc'][$k] ); } else { $a = array('asc' => NULL); $a += array( 'desc' => $p['asc-desc'][$k] ); } $a = array_merge( ( is_array( $p['scroll']['gets'] ) ? $p['scroll']['gets'] : array() ) , $a ); $c = "" . $c . ""; } if ( is_array( $c ) ) { /********************** * Mulitple rows **********************/ $tr[$k] = ''; $colspan = 0; $current_colspan = 0; foreach ( $c as $kk => $cc) { $td_attr = ( strpos($kk, '|') ? substr($kk, strpos($kk, '|') + 1, strlen($kk) ) : NULL ); preg_match('/colspan=([0-9]+)/', $td_attr, $matches); $colspan = (isset( $matches[1] ) ? $matches[1] : 1); unset($matches); preg_match('/rowspan=([0-9]+)/', $td_attr, $matches); $rowspan = (isset( $matches[1] ) ? $matches[1] : 1); unset($matches); $kk = ( strpos($kk, '|') ? substr($kk, 0, strpos($kk, '|')) : $kk ); $tr[$k] .= "". $cc .""; if ( $rowspan > 1 && ! isset ( $num_columns )) { for( $i=1; $i < $rowspan; $i++ ) { $col_num_translate[$i][$current_colspan + 1] = $colspan; } } $rowspan_additions = 0; for($i=1; $i <= $colspan; $i++) { //echo $current_colspan + $i; $row_diff = ( isset ( $num_columns ) ? 0 : $col_num_translate[1][$current_colspan + $i]); if ( $column_titles[$current_colspan + $i + $row_diff ] == NULL ) $column_titles[$current_colspan + $i + $row_diff ] = $cc; } $current_colspan += $colspan; } if ( ! isset ( $num_columns ) ) { $num_columns = $current_colspan; } } else { $s .= "$c"; } print_p($col_num_translate); print_p($column_titles); } $s .= ( isset($tr) ? implode("", $tr) : '' ); unset($tr); $s .= ""; } /** * Create Scroll navigation */ if ( isset( $p['scroll'] ) /* && ( $p['scroll']['found_rows'] > $p['scroll']['rows'] ) */ ) { $scroll = "
    Total " . $p['scroll']['found_rows'] . " | Displaying " . ( $p['scroll']['start'] + 1 ) . " to " . ( ( $tmp = $p['scroll']['start'] + $p['scroll']['rows'] ) > $p['scroll']['found_rows'] ? $p['scroll']['found_rows'] : $tmp ) . "
    "; $scroll .= "
    "; $scroll .= ( $p['scroll']['start'] > 0 ? " ( - $p['scroll']['rows'] + $p['scroll']['start'] )) ) ) . "'>prev" : "prev" ); $scroll .= " | "; $scroll .= ( $p['scroll']['found_rows'] > ( $p['scroll']['rows'] + $p['scroll']['start'] ) ? " ( $p['scroll']['rows'] + $p['scroll']['start'] ) ) ) ) . "'>next" : "next" ); $scroll .= "
    "; } /** * Summary information TFOOT * By W3 this has to be before TBODY */ if ( isset( $p['summary'] ) || isset( $scroll ) ) { $s .= ""; if ( isset( $p['summary'] ) ) { $s .= ""; foreach( $p['column_titles'] as $k => $c ) { if ( is_array( $c ) ) { $tr[$k] = ''; foreach( $c as $kk => $cc ) { $td_attr = ( strpos($kk, '|') ? substr($kk, strpos($kk, '|') + 1, strlen($kk) ) : NULL ); $kk = ( strpos($kk, '|') ? substr($kk, 0, strpos($kk, '|')) : $kk ); $tr[$k] .= "". ( isset( $p['summary'][$kk] ) ? $p['summary'][$kk] : ' ' ) .""; } } else { $s .= "" . $p['summary'][$k] . ""; } } $s .= ( isset($tr) ? implode("", $tr) : '' ); $s .= ""; } if ( isset($scroll) ) { $s .= "" . $scroll . ""; } $s .= ""; } /** * Create Table Rows Attr */ if( ! isset( $p['tr_attr'][0], $p['tr_attr'][1] ) ) { $p['tr_attr'] = array('od', 'ev'); } /** * Create Rows */ $s .= ""; if($p['data'] == NULL) { $s .= "No Results"; } else { $i=0; foreach( $p['data'] as $r ) { $i = ($i>1) ? $i=0 : $i; $s .= ""; foreach( $p['column_titles'] as $k => $c) { if ( is_array( $c ) ) { $tr[$k] = ''; foreach( $c as $kk => $cc) { $td_attr = ( strpos($kk, '|') ? substr($kk, strpos($kk, '|') + 1, strlen($kk) ) : NULL ); $kk = ( strpos($kk, '|') ? substr($kk, 0, strpos($kk, '|')) : $kk ); $tr[$k] .= "". ( is_array( $r[$kk] ) ? print_list( $r[$kk] ) : $r[$kk] ) .""; } } else { $s .= "". ( is_array( $r[$k] ) ? print_list($r[$k]) : $r[$k] ) .""; } } $s .= ( isset($tr) ? implode("", $tr) : '' ); $s .= ""; $i++; unset($tr); } } $s .= ""; $s .= ""; return $s; } ?>[/CODE] [CODE=example.code]default_style_table_class != NULL ) { $p['attr']['class'] = $this->default_style_table_class; $p['attr']['cellspacing'] = $this->default_table_cellspacing; } if ( isset($p['attr']) ) { foreach ( $p['attr'] as $k => $v ) { $s .= ' '.$k.'="'.$v.'"'; } } $s .=">"; /******************** * ********************/ if ( isset( $p['groups'] ) ) { $status = "
      " . "
    • " . ( $p['vars']['status'] !== NULL ? "All" : "All" ) . "
    • "; foreach ( $p['groups'] as $k => $v ) { if ( $k === $p['vars']['status'] ) { $status .= "
    • $v
    • "; } else { $status .= "
    • $v
    • "; } } $status .= "
        "; } $s .= ( isset( $p['caption'] ) ? '' . $p['caption'] . ( isset($status) ? $status : NULL ) . '' : ''); /******************** * ********************/ if ( !isset( $p['titles'] ) && isset( $p['data'][0] ) ) { /********************** * Default **********************/ foreach( $p['data'][0] as $c => $v ) { $p['titles'][$c] = $c; } } if ( isset($p['titles']) ) { $s .= ""; $num_col = 0; foreach( $p['titles'] as $k => $c ) { if ( $c !== NULL ) { /*********** * ***********/ //{{{{ /********************* * TH attributes *********************/ $td_attr = ( strpos($c, '|') ? substr($c, strpos($c, '|') + 1, strlen($c) ) : NULL ); /********************* * Colspan *********************/ preg_match('/colspan=([0-9]+)/', $td_attr, $matches); $colspan = (isset( $matches[1] ) ? $matches[1] : 1); $num_col += $colspan; unset($matches); /********************* * Rowspan *********************/ preg_match('/rowspan=([0-9]+)/', $td_attr, $matches); $rowspan = (isset( $matches[1] ) ? $matches[1] : 1); unset($matches); //}}}} $c = ( strpos($c, '|') ? substr($c, 0, strpos($c, '|')) : $c ); if ( isset($p['ordinate'][$k]) && array_key_exists( 'asc', $p['vars'] ) ) { /************************ * Ordinate (asc, desc) ************************/ if ( $p['vars']['desc'] != NULL && $p['vars']['desc'] == $p['ordinate'][$k] ) { $a = array('desc' => NULL); $a += array( 'asc' => $p['ordinate'][$k] ); } else { $a = array('asc' => NULL); $a += array( 'desc' => $p['ordinate'][$k] ); } $a = array_merge( ( is_array( $p['vars'] ) ? $p['vars'] : array() ) , $a ); $c = "" . $c . ""; $s .= "$c"; } else { /************************ * No Ordinate ************************/ $s .= "$c"; } } } $s .= ""; } /******************** * ********************/ if ( isset( $p['summary'] ) || isset( $p['paginate'] ) ) { $s .= ""; /********************** * Column Summaries **********************/ if ( isset( $p['summary'] ) ) { $s .= ""; foreach( $p['titles'] as $k => $c ) { if ( isset( $p['summary'][$k] ) ) { $s .= "" . $p['summary'][$k] . ""; } else { $s .= " "; } } $s .= ""; } /************************ * Paginate ************************/ if ( isset( $p['paginate'] ) && ( $p['paginate']['found_rows'] > $p['paginate']['limit'] ) ) { $s .= "" . "
        " . "
        " . "" . "" . "
        " . "Total " . $p['paginate']['found_rows'] . " | Displaying " . ( $p['paginate']['start'] + 1 ) . " to " . ( ( $tmp = $p['paginate']['start'] + $p['paginate']['limit'] ) > $p['paginate']['found_rows'] ? $p['paginate']['found_rows'] : $tmp ) . "
        "; $s .= "
        " . ( $p['paginate']['start'] > 0 ? " ( - $p['paginate']['limit'] + $p['paginate']['start'] ) ) ) ) . "'>prev" : "prev" ) . " | " . ( $p['paginate']['found_rows'] > ( $p['paginate']['limit'] + $p['paginate']['start'] ) ? " ( $p['paginate']['limit'] + $p['paginate']['start'] )) ) ) . "'>next" : "next" ) . "
        " . ""; } $s .= ""; } /******************** * ********************/ if ( ! isset( $p['tr_attr'][0], $p['tr_attr'][1] ) ) { $p['tr_attr'] = array('od', 'ev'); } if($p['data'] == NULL) { /****************** * Empty resultset ******************/ $s .= "No Results"; } else if ( isset( $p['structure'] ) ) { /*************************** * Resultset: Multiple rows ***************************/ $i=0; foreach( $p['data'] as $r ) { $i = ($i>1) ? $i=0 : $i; foreach( $p['structure'] as $k => $c ) { if ( is_array($c) ) { $s .= ""; foreach( $c as $kk => $cc ) { $td_attr = ( strpos($kk, '|') ? substr($kk, strpos($kk, '|') + 1, strlen($kk) ) : NULL ); $kk = ( strpos($kk, '|') ? substr($kk, 0, strpos($kk, '|')) : $kk ); if ( isset ($r[$kk]) && is_string($r[$kk]) && strpos($r[$kk], '.gif')) { /******************* * Img, (gif) *******************/ $r[$kk] = ""; } $s .= "" . ( isset( $r[$kk] ) ? ( is_array( $r[$kk] ) ? $this->html_list( $r[$kk] ) : $r[$kk] ) : ' ' ) . ""; } $s .= ""; } } $i++; } } else { /************************ * Resultset: Single row ************************/ $i=0; foreach( $p['data'] as $r ) { $i = ($i>1) ? $i=0 : $i; $s .= ""; foreach( $p['titles'] as $k => $c ) { if ( isset ($r[$k]) && is_string($r[$k]) && strpos($r[$k], '.gif')) { /******************* * Img, (gif) *******************/ $r[$k] = ""; } $s .= "". ( isset($r[$k]) ? ( is_array($r[$k]) ? $this->html_list( $r[$k] ) : $r[$k] ) : ' ' ) .""; } $s .= ""; } } $s .= ""; return $s; } ?>[/CODE] [CODE=example.code]userid . " ) " . ( $this->status !== NULL ? " AND if ( expire < NOW(), " . EXPIRED . ", status ) = " . $this->status : "" ) . " ORDER BY " . ( $this->order_field == NULL ? $default_order_field : $this->order_field ) . " " . $this->order . " LIMIT " . $this->start . ", " . $this->limit; if ( $r['data'] = $this->GetAll($q) ) { foreach( $r['data'] as &$o ) { $o['url'] = array( url::cv( $o['proid'], $o['title'] ) => $o['title'] ); $o['time'] = def::datediff( $o['time'] ); $o['status']= def::status_cv( $o['status'] ); //( !$o['hide'] ? def::datediff($o['datediff']) : 'Inactive' ); $o['action']= array( url::cv( $o['proid'] ) . "edit" => 'edit' ); $o['delete']= array( url::cv( $o['proid'] ) . "delete" => WWW_STYLE . "graphics/bin.gif" ); $o['graphic'] = def::graphic(GIF_MALE_CV); } } /********************** * Paginate **********************/ $r['paginate'] = array( 'found_rows' => $this->FoundRows(), 'start' => $this->start, 'limit' => $this->limit, 'url_prefix' => WWW_MY . 'cvs/' ); /********************** * Vars **********************/ $r['vars'] = $this->getvars(); if ( ! isset ( $r['vars']['asc'] ) && !isset( $r['vars']['desc'] ) ) { $r['vars']['desc'] = $default_order_field; } /********************** * Description **********************/ $r['caption'] = "My CV's create a new personal cv advert"; /********************** * Groups (top tabs) **********************/ $r['groups'] = def::status_cv(); /********************************* * Col Ascending and Descending * `column key` => `db column name` *********************************/ $r['ordinate'] = array( 'time'=> 'expire', 'expire_date'=> 'expire', 'url' => 'title' ); return $r; } $r['cvs'] = $c->cv(); $r['cvs']['titles'] = array( 'pic' => '', 'views' => 'Views', 'feedback' => 'Feedback', 'status' => 'Status', 'time' => 'Expires|colspan=2 width="100px"', 'expire_date'=> NULL, 'action' => 'Action|colspan=2', 'delete' => NULL ); $r['cvs']['structure'] = array( array( 'graphic|rowspan=2' => '', 'url|colspan=5' => NULL, 'action|rowspan=2' => 'Action|colspan=2', 'delete|rowspan=2' => NULL ), array( "views|align='right'" => 'Views', "feedback|align='right'" => 'Feedback', "status|align='right'" => 'Status', "time|align='right'" => 'Expires|colspan=2 width="100px"', "expire_date|align='right'" => NULL ) ); ?>[/CODE]

        Comments

        ninestab123
        ninest123 One canada goose pas cher gucci outlet thing
        Created 21/07/16
        Title*
        Comment

        Prove you are not a robot

        To prove you are not a robot, please type in the six character code you see in the picture below
        Security confirmation codeI can't see this!
        Contact
        Name*
        Email never shown*
        Home Page

    Author

    Andrew Dodson
    Since:Feb 2007

    Comment | flag

    Categories

    Bookmark and Share