473,466 Members | 1,508 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Trouble getting SQL SUM to work with $variable table name

2 New Member
Hi, I'm trying to return the sum of balances from a table and can get the following code to work when using a specific table name

$qry = mysql_query("SELECT SUM(Balance) AS total FROM table1 ");
$row = mysql_fetch_assoc($qry);
echo $row['total'];

The problem im having is that my table name changes and this needs to be a variable but when i use the following code I get no result

$table="table1";
$qry = mysql_query(" SELECT SUM(Balance) AS total FROM $table ");
$row = mysql_fetch_assoc($qry);
echo $row['total'];

Can anyone offer some help please?
Oct 30 '14 #1
1 1252
Andyish56
2 New Member
Sorry I've found the error which was not in the code posted
Oct 30 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Rudi | last post by:
Hello Forum ! I want to have the tablename "dbo.Enbxxxx" as an additional parameter for a procedure like this: ALTER Procedure prcSucheUNR ( @UNR int ) As
6
by: vbnetrookie | last post by:
I have a table name in SQL Server 2000 that has a space in it ex: aim international I had trouble just in the query analyzer with this..I had to place the name in brackets for it to work. But...
2
by: James | last post by:
Can anyone please shed some light on the following... I have a framework that uses dynamically created tables, named using an incremental "attribute set ID", as follows: attrdata_1 attrdata_2...
4
by: dixie | last post by:
I want to write a query where one of the two tables in it is variable and its name is picked up from a text box control on an open form. The query is very simple and is only a select query with...
11
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result =...
2
by: BulbFresh | last post by:
Hi, I'm a novice Access user and have a simple question but can't seem to find the answer. I have tables imported and named by the user on import e.g. January. I then need to run a query on the...
1
by: ishakteyran | last post by:
hi all; i am using a db2 database on RAD platform and need to generate tables (names of them will be determined by users.) so i thought i can do this with a stored procedure which takes the table...
3
by: Andrea Raimondi | last post by:
Hello peers! I'm working on this application and I'm in need for some thoughtful advice :-p I have an SQLDataSource with params, select, etc. One of my params is the table name, which can be...
1
by: Dreea | last post by:
Hello all What is the appropriate syntax for declaring a cursor for a table name that is passed as a parameter to a procedure? I tried several combination and it doesn't seem to work. CREATE...
4
by: James Wigginton | last post by:
Hi I have a database which archives data by financial year. I want to be able to run a query and append the data to a table which is named after the financial year, expendituresFY. The problem I...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.