ユーザーがテーブル内のデータのソート方法と、それが増加または減少するかどうかを設定できるフォームがあります
http://damiensplace.co.uk/test/requestTableDisplay.htm
ただし、ユーザーにフィールド (Age Grade) フォーム セット変数を除外することを選択してもらいたいのですが、これを行う方法について頭を悩ませていますが、基本的に 2 ロットのコードを記述する必要があるため、私が思いつく唯一の方法は適切ではありません。トリックがありませんか?
<html><head><title>MySQL Table Viewer</title></head><body>
<?php
$db_host = '****';
$db_user = '***';
$db_pwd = '***';
$sortOn = $_POST['SortOn'];
$sortIn = $_POST['SortIn'];
$database = '****';
$table = '***';
if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
if (!mysql_select_db($database))
die("Can't select database");
// sending query
$result = mysql_query("SELECT * FROM {$table} order by {$sortOn} {$sortIn}");
if (!$result) {
die("Query to show fields from table failed");
}
$fields_num = mysql_num_fields($result);
echo "<h1>Table: {$table}</h1>";
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>\n";
}
mysql_free_result($result);
?>
</body></html>
誰かが私を正しい方向に向けることができれば、私は最も感謝しています