PHP回显日期和查询中的数字

时间:2013-08-16 10:46:19

标签: php database mysqli echo

您好我已经尝试通过编写小型网络应用程序来向我展示销售数据。我有一个查询,我现在的工作,因为我测试了它,但我希望它回应日期匹配和在该日期找到的行/结果的数量。这就是我到目前为止所拥有的

<?php
$con=mysqli_connect("host","user","password","database");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT * FROM matched WHERE datematched IN (
    SELECT datematched FROM matched GROUP BY datematched HAVING count(*) > 1");

while($row = mysqli_fetch_array($result))

  {
  echo "['";
 echo "" . $date['datematched'] . "', ";
  echo "" . $num_rows . "],";

   }

mysqli_close($con);
?>

我知道我在这里做错了什么。莱恩

编辑:

<?php
$con=mysqli_connect("host","user","password","database");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT * FROM matched WHERE datematched IN (
    SELECT datematched FROM matched GROUP BY datematched HAVING count(*) > 1");


 echo "['";
 echo " 16/08/2013 ', ";
  echo "12345}],";


mysqli_close($con);
?>

好的,我刚刚检查了我的回声,他们工作我输入了一些数据,所以我需要的是找到一种方法来获取已找到的datematched的信息,然后找到已经找到的行数。谢谢Ryan

3 个答案:

答案 0 :(得分:1)

首先,您需要对查询进行调整,以便它具有您期望的行数。

$result = mysqli_query($con,"SELECT datematched, COUNT(*) as num_rows "
       . "FROM matched GROUP BY datematched HAVING num_rows > 0");

然后您可以按如下方式显示数据

while($row = mysqli_fetch_array($result))
{
 echo $row['datematched'] . ",";
 echo $row['num_rows'];
}

答案 1 :(得分:0)

如果您的SQL查询是完美的,那么您应该像这样编写

while($row = mysqli_fetch_array($result))

  {
  echo "['";
 echo "" . $row['datematched'] . "', ";
  echo  "" . $row['num_rows'] . "', ";

   }

请在mysql查询中设置列。

答案 2 :(得分:-1)

<?php
$query=mysqli_query($con,"SELECT datematched FROM matched GROUP BY datematched");
$num=mysqli_num_rows($query);
if($num>1)
{ 
$result = mysqli_query($con,"SELECT * FROM matched");
$num_rows=mysqli_num_rows($result);
while($row = mysqli_fetch_array($result))
{
echo '['; echo $row['datematched']; echo $num_rows; echo ']';
}
}