所以,我有一个复选框,允许用户选择他们想要查看的列。所以,如果用户想要例如只选择2列(比如TicketID和Category),它将只显示ID和票据类别的数据。这是我到目前为止有:通过用户在php中选择数据库数据填充html表
形式:
- Ticket ID
- Category
- Priority
- Status
- Initial Description
- Submitted Date
- Status Description
viewTicketTable($_SESSION['userID'],$_POST['filter']);
?>
viewticketTable功能:
function viewTicketTable($userID,$columns) {
/* Accepts $userID which will identify the tickets related with the user and
$columns which will filter only the columns that are required and outputs the
table with the columns passed through. */
/*
$columns_array = explode(',', $columns);
foreach($array as $array){
echo $array;
} */
foreach($columns as $filter) {
$filter = $filter . ',' ;
}
$filter = substr($filter, 0, -1);
$query = mysql_query("
SELECT $filter
FROM Ticket
LEFT JOIN TicketHistory
ON Ticket.TicketID = TicketHistory.TicketID
WHERE CustomerID = $userID;
");
/* Creation of the table */
echo '
';
foreach($columns as $tableHeader) {
$tableHeader = '
' . $tableHeader . '' ;echo $tableHeader;
}
echo '
';
/*Looping through the script to print out all the information.*/
while ($row = mysql_fetch_array($query) or die(mysql_error())) {
echo '
';foreach($columns as $field) {
echo '
' . $row[$field] . '';}
echo '
';
}
echo '
';}
的问题存在于while循环。行[$ field]只填充最后一列,而不是填充它们全部。任何帮助?
2013-04-12
Hugo
+0
在别的之前;你需要做一些事情来加强对SQL注入的查询。现在任何人都有足够的印记来使用浏览器来检查和编辑你的页面,可能会将某个过滤器输入值更改为恶意。 –
+0
现在我只是想它的工作...但是,感谢您的提醒:) –