Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 要打印通过html表单查询的sql表的选定列吗_Php_Html_Sql - Fatal编程技术网

Php 要打印通过html表单查询的sql表的选定列吗

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

我只想打印网站上mysql表中通过html表单查询的选定列。 $column[]存储用户希望在web上看到的列。 那么如何从mysql表中选择特定的列

在php文件中

<?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