-2

Hi I have trying to learn php by writing little web app for showing me sales data. I have got a query which i now works as i have tested it but i want it to echo the datematched and the number of rows/results found with that date. This is what I have so far

<?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);
?>

I know i am doing something wrong here. ryan

EDIT:

<?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);
?>

Okay i have just checked my echo and they work i put in some data so all i need is to find a way of getting the information of the datematched that has been found and then the number of rows that has been found with that. Thanks Ryan

4

3 回答 3

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'];
}
于 2013-08-16T10:56:17.370 回答
0

如果你的 sql 查询是完美的,那么你应该这样写

while($row = mysqli_fetch_array($result))

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

   }

请按照您在 mysql 查询中的设置设置您的列。

于 2013-08-16T10:49:55.030 回答
-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 ']';
}
} 
于 2013-08-16T10:54:59.100 回答