0
<?php
                    $connection = new mysqli("localhost","root","", "inventory");
                    $dash_sales_query = "SELECT sum(Total) FROM salesp";
                    $dash_sales_query_run = mysqli_query($connection,$dash_sales_query) or die(mysqli_error());
        
                        if($sales_total = mysqli_num_rows($dash_sales_query_run))
                        {
                            echo '<span class="bold">'.$sales_total.'</span>';
                        }
                        else
                        {
                            echo '<span class="bold">No Data</span>';
                        }
                    ?>

hi im beginner and i making a analytics for the system in websites. i really want to show the total price of "total (data)". so i sum it as you can see, but it shows only 1. what is my error?? thankyou very much.

1 Answer 1

2

The function mysqli_num_rows counts the total amount of rows of the query result, but you want to see the result of the query. It shows 1, because mysql is giving you one row with the result.

Try using this:

$result = mysqli_fetch_assoc($dash_sales_query_run);
print_r($result);

Another tip: give your SUM() in the query an alias, so it is easier to read in the result.
Like this: "SELECT SUM(Total) AS total FROM salesp";

Sign up to request clarification or add additional context in comments.

2 Comments

thankyou very much! HJS85. Have good day borther
Hi @EldrianKo, mark answer as correct if that worked for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.