html - PHP-How to echo my own table header using this code? -
i new @ programming php. ive been using code echo mysql database , html table. code echo's table header's database. want echo own html code in table heather.
in other words want imput own text in <th></th>
instead of displaying data database.
thanks in advance.
<?php $db_host = 'localhost'; $db_user = 'my user'; $db_pwd = 'my pwd'; $database = 'my db'; $table = 'subcontractor'; if (!mysql_connect($db_host, $db_user, $db_pwd)) die("can't connect database"); if (!mysql_select_db($database)) die("can't select database"); // sending query $result = mysql_query("select * {$table}"); if (!$result) { die("query show fields table failed"); } $fields_num = mysql_num_fields($result); echo "<table class='table table-bordered table-striped mb-none' id='datatable-tabletools' data-swf-path='assets/vendor/jquery-datatables/extras/tabletools/swf/copy_csv_xls_pdf.swf' >"; // printing table headers echo "<thead>"; for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<th>{$field->name}</th>"; } echo "</thead>"; // printing table rows while($row = mysql_fetch_row($result)) { echo "<tbody>"; echo "<tr>"; echo "</thead>"; // $row array... foreach( .. ) puts every element // of $row $cell variable foreach($row $cell) echo "<td>$cell</td>"; echo "</tr>"; echo "</tbody>"; } mysql_free_result($result); ?> </div>
thank works perfect. there way make php skip column table on db? –
yes, change query
$result = mysql_query("select * {$table}");
for example by
$result = mysql_query("select `name`,`email`,`address` {$table}");
Comments
Post a Comment