0
$query = mysqli_query($conn,SELECT `date`,`name`,`surname`, COUNT(*) AS abc FROM `trial` WHERE `name`='asd' GROUP BY `date`,`name`,`surname` ORDER BY `date` DESC);

<?php while ($row = mysqli_fetch_array($query)) : ?>
     <td><?php echo $row['abc']; ?></td>
     <td><?php echo $row['Can I print a value returned from a different query, not abc? ']; ?></td>

 <?php endwhile; ?>

Can I run a separate query for the second row instead?

Barmar
  • 741,623
  • 53
  • 500
  • 612

1 Answers1

1

Combine them into a single query that gets both counts for each surname.

<?php
$query = mysqli_query($conn,"
    SELECT `date`,`surname`, SUM(name = 'asd') AS asd_count, SUM(name = 'opr') AS opr_count
    FROM `trial` 
    WHERE `name`= IN ('asd', 'opr')
    GROUP BY `date`,`surname`
    ORDER BY `date` DESC");
$result = mysqli_query($conn, $query);
while ($row = mysqli_fetch_assoc($result)): ?>
     <tr>
     <td><?php echo $row['date']; ?></td>
     <td><?php echo $row['surname']; ?></td>
     <td><?php echo $row['asd_count']; ?></td>
     <td><?php echo $row['opr_count']; ?></td>
     </tr>
<?php endwhile; ?>

See multiple query same table but in different columns mysql

You also need to start a new <tr> for each row returned by the query.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thank you very much, I understand very well. The query works fine, but there is a problem. It does not show data with the same date, same last name but different name on the same line. So it shows as asd_count and opr_count on two different rows down. I want it to appear side by side on the same row. – ibrahim özden Sep 01 '20 at 16:12
  • They should. But it was missing `` to start a new row. I added that. – Barmar Sep 01 '20 at 16:14
  • Not exactly. I did this, but there is a problem with the mysql query. It would be great if I could show it with a photo. – ibrahim özden Sep 01 '20 at 16:16
  • Give a link to an uploaded screenshot. – Barmar Sep 01 '20 at 16:19