num_rows == 0 ) return ""; $tb = "\n"; $result_obj->data_seek(0); // make sure we start from 1st row $header_done = false; $total=0.0; $cols=0; while( $data = $result_obj->fetch_assoc() ) // each row as asso array {// table header if (!$header_done) // table headers { $tb .= ''; $cols=count($data); foreach($data as $attr => $value) { $tb .= ""; } $tb .= "\n"; $header_done = true; } $total += $data[$amt_name]; // table rows $tb .= "\n"; } $total=number_format($total, 2, '.', ''); $tb .=""; return ($tb . "
$attr
"; // table cells $tb .= implode("", $data); $tb .= "
Total: $total
\n"); } function htmlTable(&$result_obj, $class) { if ( $result_obj->num_rows == 0 ) return ""; $tb = "\n"; $result_obj->data_seek(0); // make sure we start from 1st row $header_done = false; while( $data = $result_obj->fetch_assoc() ) // each row as asso array {// table header if (!$header_done) // table headers { $tb .= ''; foreach($data as $attr => $value) { $tb .= ""; } $tb .= "\n"; $header_done = true; } // table rows $tb .= "\n"; } return ($tb . "
$attr
"; // table cells $tb .= implode("", $data); $tb .= "
\n"); } // htmlCart takes a query restult set and // returns html code for a shopping cart // allowing quantity updates function htmlCart(&$result_obj, $id_name, $amt_name, $qty_name, $action, $class) { if ( $result_obj->num_rows == 0 ) return ""; $cart = "
\n"; $result_obj->data_seek(0); // make sure we start from 1st row $header_done = false; $total=0.0; $cols=0; while( $data = $result_obj->fetch_assoc() ) // each row as asso array {// table header if (!$header_done) // table headers { $cart .= ''; $cols=count($data); foreach($data as $attr => $value) { $cart .= ""; } $cart .= "\n"; $header_done = true; reset($data); } $total += $data[$amt_name]; $q=$data[$qty_name]; $id=$data[$id_name]; $qty_code=""; // table rows $cart .= ''; foreach($data as $attr => $value) { if ( $attr == $qty_name ) $cart .= $qty_code; else $cart .= ""; } $cart .= "\n"; } $total=number_format($total, 2, '.', ''); $cart .=""; return ($cart . "
$attr
$value
Total: $total
  
\n "); } // see also: $row=result_obj->fetch_row // indexed from 0 // $row=$result_obj->fetch_object() // as object properties // You can obtain meta info for each column // $info_obj = $result->fetch_field_direct(1); // $info_obj->name; // $info_obj->table; // $info_obj->max_length; // $info_obj->flags; // $info_obj->type; ?>