我必须进行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 | [email protected]
JOHN | [email protected]
TIM | [email protected]
我尝试了这段代码:
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($ result)
代替
mysql_fetch_array($ result)
要么
将索引与数组参数一起用于mysql_fetch_array($ result)
如$ rows [0],$ rows [1]
关于php - mysql选择,计数,左联接并显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31985005/