Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8980217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:01:34+00:00 2026-06-15T20:01:34+00:00

I have a MySQL table payment where I store all the payment related data

  • 0

I have a MySQL table payment where I store all the payment related data of my client. The table fields are: fileNo, clientName, billNo, billAmount, status. I want to build a search form where I will input the fileNo or the clientName, which will yield a table fetching all the records for that file number or the client name where status = 0 (unpaid). Here billAmount is a floating point number.

I am no good in MySQL, but here is my version of the SQL by fileNo

$sql = "SELECT * FROM `payment` WHERE `fileNo` = '$fileNo' AND `status` = '0'";

SQL by clientName

$sql = "SELECT * FROM `payment` WHERE `clientName` = '$clientName' AND `status` = '0'";

either way I make the query, I will also need to show the total unpaid amount against that fileNo or clientName.

From my understanding, the SUM() operation should be something like this:

$sql = "SELECT SUM(billAmount) AS `unpaid` WHERE `fileNo` = '$fileNo' AND `status` = '0'";

or

$sql = "SELECT SUM(billAmount) AS `unpaid` WHERE `clientName` = '$clientName' AND `status` = '0'";

My question is, am I correct with my SUM() operation? And how do I get the total unpaid amount that I selected as unpaid? can I store it in a variable?

Any idea, suggestions or resource link will be much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:01:36+00:00Added an answer on June 15, 2026 at 8:01 pm

    i think u should use the second query but u missed WHEre clause

       $sql = "SELECT SUM(billAmount) AS `unpaid` FROM payment WHERE `clientName` = '$clientName' AND `status` = '0'";
    

    your total amount unpaid yes u cant get it as variable like that

     $result = mysql_query($sql);
     $row = mysql_fetch_array($result);
       ehco   $row['unpaid'] ;          <------ this will give you the unpaid amount.
    

    of course after u fetch your query .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mysql table named payment and there is a field in it
I have MySQL table that contains all messages from user to user: id |
I have a MySQL table of billing records. Each entry records either a payment
I have mysql table with following fields id (which auto increments) title,name,age,institution,iod the fields
I have a table called payment which adds all the payment entries. I have
I have a mysql table name payment (contains payments made by the customer) and
I have a MySQL table like this: Payments +----+---------------------+---------+ | id | date (sorted
I have mysql table that has a column that stores xml as a string.
I have MySQL InnoDB table utf-8 encoded. This table has only id and name
I have a MySQL table and would like to return the rows based on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.