473,387 Members | 1,304 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Trouble getting SQL SUM to work with $variable table name

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 1249
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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...

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.