我是新的php和sql我试图选择一个用户名并计算他的总列名并显示它。我有点混淆如何做到这一点。请帮帮我们。非常感谢你。
<?php
if( isset($_POST['query']) ){
$query = $_POST['query'];
$raw_results = mysql_query(
"SELECT *
FROM inventory
WHERE
(`serialproductkey` LIKE '%".$query."%') OR
(`employeename` LIKE '%".$query."%')"
) or die(mysql_error());
if( mysql_num_rows($raw_results) > 0 ){
// and this code that i need to combine with the search part
$tae = "SELECT SUM(total) AS TotalItemsOrdered FROM inventory";
答案 0 :(得分:1)
mysql_*
函数已弃用。使用mysqli_*
或pdo
,read more '%".$query."%'
很危险......风险SQL_injection 您问题的可能解决方案是
$raw_results = mysql_query(
"SELECT employeename, SUM(total) AS TotalItemsOrdered
FROM inventory
WHERE
(serialproductkey LIKE '%".mysql_real_escape_string($query)."%') OR
(employeename LIKE '%".mysql_real_escape_string($query)."%')
GROUP BY employeename"
) or die(mysql_error());
答案 1 :(得分:0)
SELECT SUM(total) AS TotalItemsOrdered
FROM inventory
WHERE (`serialproductkey` LIKE '%".$query."%') OR
(`employeename` LIKE '%".$query."%')