-1

我正在尝试table formdatabase. 它不显示表格,而是打印出第一个带有“无法显示列”的行。至少它应该在浏览器上显示表格形式。MySQLPHPjob_order_numberdatabasejob_order_number

CSS

<style>
table.db-table {
 border-right:1px solid #ccc; 
 border-bottom:1px solid #ccc;
}

table.db-table th { 
 background:#eee; 
 padding:5px; 
 border-left:1px solid #ccc; 
 border-top:1px solid #ccc; 
}
table.db-table td { 
 padding:5px; 
 border-left:1px solid #ccc; 
 border-top:1px solid #ccc; 
}
</style>

PHP

<?php 
// connect to the MySQL database
require("connect.php");
if(isset($_POST['submit'])){
$_POST['category_code'] = mysql_real_escape_string($_POST['category_code']);
$sql = "SELECT * FROM CS_JOBS WHERE category_code =".$_POST['category_code'];
$result = mysql_query($sql);

while ($row = mysql_fetch_array($result)) {
    $table = $row[0];
    echo '<h3>'.$table.'</h3>';
    $result2 = mysql_query('SHOW COLUMNS FROM '.$table) or die('Cannot show   columns from '.$table);
    if(mysql_num_rows($result2)) {
        echo '<table cellpadding="0" cellspacing="0" class="db-table">';
        echo '<tr><th>Job Order Number</th><th>New Job</th><th>Job Title</th><th>Location</th><th>Close Date</th><th>Category_code</th></tr>';
        }  
        while($row2 = my_sql_fetch_row($result2)) {
            echo '<tr>';
            foreach($row2 as $key => $value) {
            echo '<td>'.$value.'</td>';
            }
            echo '</tr>';
        }
        echo '</table><br />';
        }
    }           
?>
4

1 回答 1

0

最好将您的问题清楚地发布在您想要的内容上,

并请发布数据库表格格式以正确指导您

这是我所理解的答案

<?php 
function getColoumn($table) { 
     $result = mysql_query("SHOW COLUMNS FROM ". $table); 
     if (!$result) { 
    echo 'Could not run query: '.mysql_error(); 
  } 
  $fieldnames=array(); 
  if (mysql_num_rows($result) > 0) { 
    while ($row = mysql_fetch_assoc($result)) { 
      $fieldnames[] = $row['Field']; 
    } 
  }
  return $fieldnames; 
} 
?> 

这用于获取表的所有列信息

于 2013-08-07T17:57:09.503 回答