Php 要打印通过html表单查询的sql表的选定列吗
我只想打印网站上mysql表中通过html表单查询的选定列。 $column[]存储用户希望在web上看到的列。 那么如何从mysql表中选择特定的列 在php文件中Php 要打印通过html表单查询的sql表的选定列吗,php,html,sql,Php,Html,Sql,我只想打印网站上mysql表中通过html表单查询的选定列。 $column[]存储用户希望在web上看到的列。 那么如何从mysql表中选择特定的列 在php文件中 <?php @ $db = new mysqli('localhost', 'user', 'passwd', 'myDatabase'); $column = $_POST['columns']; // column passed through html $query = "select * from pr
<?php
@ $db = new mysqli('localhost', 'user', 'passwd', 'myDatabase');
$column = $_POST['columns']; // column passed through html
$query = "select * from primers" ;
$result = $db->query($query);
$num_results = $result->num_rows;
for($i=0; $i<$fields_num; $i++)
{
$field = mysqli_fetch_field($result);
echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
while($row = mysqli_fetch_row($result))
{
echo "<tr>";
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>\n";
}
?>
现在,我要选择在$column array中指定的列名来代替*
帮帮我。谢谢你试试这样的东西:
$query = "select " . (empty($column) ? '*' : implode(', ', $column)) . " from primers";
您正在使用哪些rdbms?@Shnugo
$db=new mysql()i
@MasivuyeCokile是。应该看到:-D