How do I fix it? - PHP - SitePoint Forums | Web Development & Design Community

2022-09-09 22:41:35 By : Ms. Doris Li

I have three rows but it shows only one row in report table what’s the mistake 2022-09-07_210420 1063×265 14.3 KB

It’s because you are using an aggregate function COUNT(). This will consolidate the result set in to a single row.

What exactly are you trying to count in that query?

Rows The number of rows as shown below

fe958d15-6c0a-4d02-a9cc-4534fce3e5fc 1080×462 62 KB

So… let’s take a moment to look at what you’ve got.

SELECT name as n, birth as b, Cost as c, count(id) as total

You are selecting 4 things: n, b, c, and total.

Here, you expect $row to contain id, n, b, fixation_t, doctor, Implant_n, type, and c.

There’s… quite a bit missing from your query, don’t you think?

Rows The number of rows as shown below

If there is no data in the table, show msg there is not any data

It still didn’t get fix after you noticed it

Show us your updated code.

I’m not sure what the actual problem is now, but you can’t use $row['total'] in your table footer - $row doesn’t exist outside of your foreach() loop. Also you add $totalmarks to a running total, but that variable doesn’t seem to get created anywhere.

Is the problem still the same, only displaying a single row? Does the query return all the rows when you test it in phpmyadmin?

<?php $totlcount+=$totalmarks;}?>

Variable Undefined Error: $totlcount Variable Undefined Error: $totalmarks

I’m going to assume from the previous query that the database table does not contain a column total, and even if it did, the foreach has closed, so

<td colspan="3" style="text-align: left"><b> <?php echo $row['total']; ?></td>

Variable Undefined Error: $row[‘total’];

patient Report from <?php echo $fdate?> to <?php echo $tdate?>

Your query makes no limitation based on these date values.

yes it is onley show one row 2022-09-08_144235 1076×352 13.6 KB

You’ve put the count() back in to the query.

Dont use your query to count or total things if you want to show the item-line information.

Pull the item-line information with your query, and use PHP to do the totalling and counting.

You’ve already got an example in your code.

<?php $totlcount+=$totalmarks;}?>

First of all, define your count to start at 0 before the foreach. Then, on each loop of the foreach, add that item’s cost to the total. At the end of the loop, the total will have the total value of all of the items.

use PHP to do the totalling and counting

I did that and it wasn’t fix

You already have a count of the number of rows in the result set. It’s in $rowCount. Just echo it instead of $row[‘total’] (which does exist after the end of a foreach(){} loop if having count() as total in the query happened to be the solution, which it isn’t.)

Powered by Discourse, best viewed with JavaScript enabled