我必须进行 mysql 询问,并且必须按日期对具有相同值的某些单元格进行计数,并左连接其他表中的其他信息。
表1
col1 | col2 | col3
ALEX | today | finished
JOHN | today | finished
TIM | today | finished
JOHN | today | unfinished
JOHN | today | finished
TIM | tommorow | finished
表2
col4 | col5
ALEX | mail1@website.tld
JOHN | mail1@website.tld
TIM | mail1@website.tld
我尝试了这段代码:
sql="
SELECT col2
, col1
, col3
, COUNT(*)
FROM table1
LEFT
JOIN table2
ON table1.task_cine = table2.col4
WHERE table1.col3='finished'
GROUP
BY col1";
$result = mysql_query($sql) or die($sql.mysql_error());
while($rows=mysql_fetch_array($result))
{
echo "user : ";
echo $rows['col1'];
echo ", on date: ";
echo $rows['col2'];
echo " have ";
echo $row['COUNT(*)'];
echo " finished, and have email address";
echo $rows['col5'];
}
你能帮我一下吗?我正在尝试理解 php,但是很困难。
最佳答案
尝试:-
mysql_fetch_assoc($结果)
而不是 mysql_fetch_array($结果)
或
对 mysql_fetch_array($result) 使用带有数组参数的索引
作为$rows[0], $rows[1]
关于php - mysql 选择、计数、左连接和显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31985005/