Adding Values In One Column From Query Results

Nov 27, 2001

I have this query:

sum(field_value) as totalValue
FROM table_name
WHERE field_id = $id
GROUP BY field_group

the data type of field value is a decimal value, with values such as 125.00 and 150.50 stored in each record. My goal is to have totalValue be the total value of those numbers. So if I have two records that equal 125.00 and 150.50 totalValue would = 175.50.

the above query does not do this. What do I need to change here? Should I try to do this from the PHP side?

View 7 Replies


Put Query Results Into An Object / Ut The Column Name Results Into The Object And Also Put The Values Into The Object?

I am using php and postgresql.

I need a function that:

connects to a db if not already connected run the query safely put the results into an object

For example:I do a query that is 'select * from test'. I get back 2 rows...There are three columns in 'test' (id,fname,lname).

I have an object named $ep. I want to be able to put the column name results into the object and also put the values into the object. So I could do a var_dump of $ep->fname and it would show me an array with two results.

I don't want to hardcode the column names into my function. I want it to be dynamic. So regardless of what table or columns I request it will put everything into the object for me.

View 3 Replies

Adding Values From A Column

I have a table with baseball stats from each player on a team. Now on the page it shows the individual stats of each player in a table then on the bottom the total of each stat. Now I figure one way to add the columns up, which keep in mind all the stats are being called from a mysql db, would be to do like an array. But..I figure there has to be an easier way. I feel I've been out of the game for a little too long now.

View 1 Replies

Adding Results From Query 2 To Query 1 - Cannot Use Object Of Type Mysqli_result As Array

I make two queries and I'd like to add rows from query 2 to query 1. Also, suppose getResult1() returns no column called "item2"

$result1 = getResult1();
$result2 = getResult2();
foreach ($result2 as $res)


There error I get here is on line

$result1[] = $data

and reads

Fatal error: Cannot use object of type mysqli_result as array

I think I get what is happening, but I'm not quite sure how to fix it.The rows are ultimately getting converted to JSON, and I can do that that with an array of arrays.I've fixed the problem by converting $result1 into an array of arrays. I do this using a while loop and a fetch_array() call, but is there a quick way to just convert $result1 into an array of arrays instead of a record set?

View 3 Replies

Totaling Column Of Results From A Mysql Query?

I got my code running so that I can get a query result from a form where I can choose from a list of schools and also a date range that I choose.

My results come out fine.

I now need to total one of the columns in that result so that I know how much each school would receive.

The number that I need to total will vary from school to school and from month to month.

This is the code from the action file that the form uses to display the results.

// make connection
require_once(''); // Include the configuration file
// build query
$query1 = "SELECT * FROM testtable WHERE date >= '".$_POST['startdate']."' AND date <= '".$_POST['enddate']."' AND School='".$_POST['School']."'";


View 3 Replies

Displaying SQL Query Results In 3 Column Table

I would like to be able to display the results of an sql query in an html table, but the results need to be displayed in three columns, for example:

Column 1 Column 2 Column 3
Result 1 Result 2 Result 3
Result 4 Result 5 Result 6
Result 7 Result 8 Result 9

I've tried to find the answers on the internet but i can't find anything that suits my needs!

View 2 Replies

Adding Values Together From Multiple Results

I have a script that returns a set of results from a 'transaction' database table. One field is called 'amount'. What I would like to do is be able to mathmatically add the values from the results together and output a 'Grand Total' result. Code:

View 3 Replies

Display Query Results In 4 Column Html Table

I have a table that contains the states with the suburbs. An easy enough query to pull out all the suburbs in one state but I need to display them in two columns. I also have a table that holds the details of certain people, lets say nurses, living in the suburbs but the state isn't available in that table.

So what I would need is a 2 column html table split into 2 and then displayed side by side with the number of nurses displayed alongside the suburb. suburbNo. Nursessuburbnurses I know the first query is going to be Code: [Select]select * from table_suburbs where 'state'=ohiobut I am perplexed when it comes to calculating the number

View 3 Replies

Add Up Column Values During Query Possible?

if its possible to add up colums which have numbers in during a query to give the top 10 people who have earned the most, which also shows the total earned.

I have a query that gets the top 10 people with feedback like this...

PHP Code:

SELECT drivernumber, count(*) as posts from feedback where `drivernumber` GROUP BY `drivernumber` ORDER BY `posts` DESC LIMIT 10

Which works very well, it returns the top 10 people who have been left feedback and how many [posts]

The table also has a 'price' colum where the customer enters what they paid for the job.

So, using just a query, is it possible to add up all the numbers in the price colum and return the total, then display it as the top 10 people who have earned the most?

Or do I need to pull everything down in to an array and work it out?

View 1 Replies

Searching A MySQL Column That Has Comma Separated Values And Retrieving Results?

I seem to be having a problem, as my search isn't working. So, this is what I am trying to achieve:There is a column in a MySQL table that is called "sister_markets" and the user inputs data like this:BLAH, BLAH1, BLAH2Now, I want to grab this data and search each word individually (as a string) and find the result from another column in the same table (a partial match, only needs to be matching the start of the word). But for some reason, the search isn't working. It comes up with the results of the first string only, no more. The example data is : WCLD, WCLD-F, WKDJ-F, WMJW, WAIDThis is the PHP code:Code:

$pieces = explode(",", $search);


View 3 Replies

Adding A Delete Button To Query Results?

Currently I have a page in my members area that queries all the entries the logged in user has made and displays the results. The code for that is as follows:

$user_id = check_input($_SESSION['user_id']);
$con = mysql_connect("localhost","username","password");
if (!$con)


This part works perfectly. What I want to be able to do is to have each record that is displayed also have a Delete button, that when clicked will remove that record from the database. Ideally I would like to have it prompt the user to verify the action, but that's secondary to the first part.

View 5 Replies

MySQL Query - Array Places Data Into One Column In Table - Show Results In Two Columns?

I have a query, it is outputting the results into one column, I would like to have the results shown in two columns. Here is the code:


View 2 Replies

Insert Values Into Query Update Column Row To NULL In Database?

If one has a form.. with updates the database via userid, if some fields were left empty. would inserting the values into the query update the collum row to NULL in the database? If so, how can this be prevented.

View 14 Replies

Insert Checkbox Values Into Database Within A Separate Column Of The Query Separated By Commas?

I need help for this problem that I've been trying to solve for a while (I'm new in PHP). I have a form with several checkboxes whose values are pulled from a specific table of the database. I managed to display them in the form, but cannot insert their values into the table connected to that specific page since there is ony one column.I want to enter all the selected values of the checkbox into that single column separated by commas.

Here's the code:

url <BR><?php $query = "SELECT url FROM webmeasurements";
$result = mysql_query($query);
while($row = mysql_fetch_row($result))
{ $url = $row[0];
echo "<input type="checkbox" name="url" value="$row[0]" />$row[0]<br />";

View 1 Replies

Display Db Query Results Based On Values From An Array?

I have a page that displays a list of products with checkboxes and prices. The checked items go into an array called "reports". The data is then passed to the selection page, where I wish to display each product description and price based on the ID values from the checkbox array.

So what I am asking is how do I display the description and price of each product in the array (and then print a sum of their prices)? here is my code for the selection page. It is incomplets, as I have cleaned out my erroneous code.

if (isset($_POST['reports']))
foreach ($_POST['reports'] as $key => $rid)
echo "<h2>Individual Reports</h2>";


View 3 Replies

Update A Column From The Results Of A SUM From Other Table Column?

What im looking for is to update a column from table 1 using the results from the SUM of a different column in table 2 for example :

table 1

id | views |
1 | 0 |
2 | 0 |

table 2

show_id | views |
1 | 5 |
1 | 10 |
1 | 10 |
2 | 10 |
2 | 10 |
2 | 10 |

Now the two tables are connected by id and show_id there the same value; what i want is to add the sum of views from show_id to id where show_id=id

so at the end table 1 should look like these :

id | views |
1 | 25 |
2 | 30 |

I'm using mysql 5.1.30

View 1 Replies

Print Mysql Results Column By Column?

I'm fetching a couple of rows from a table, and now I need to be able to print them out the value of each row's field, followed by the values of each row from a different field, and so on. It's hard to explain, but let me give you an example.

Let's say we have a table with three fields: id - name - url. Now I want to be able to output the result in this order:


How do I loop through the results of my query in order to achieve this?

View 4 Replies

Adding Checkbox To A Combobox / Checked Values To An Array And Then Use The Elements Of That Array In Mysql Query?

I want to add check boxes inside a combo box and then use the values of the checked boxes in my sql query.

Also I need to append the checked values to an array and then use the elements of that array in my sql query.
How can I proceed?

View 1 Replies

Counting All Values In Column Without Creating A New Column?

I have downloads that are available for users. They can click the links to download the file. Once they do this, I have a query that updates the number of downloads that file has received. I need to create a query that adds up all the rows Total Downloads.

So for example: i have 3 rows:
Name - Total Downloads
First - 2
Second - 23
Third - 7

Using the query for these rows would give me an amount of 32. I don't want to have to create a new column to find the total number of downloads.

View 1 Replies

Adding A Custom INSERT Query When Adding A Comment / Post In Wordpress?

I am going to be starting a project where a client has 2 sites - 1 built in Wordpress and 1 using a proprietary CMS. The client has a post category that exists on their proprietary site and they want to be able to post in this category and it to be added to a category on on the Wordpress site and vice versa. As far as I can see, this would be a fairy complex - especially as the comments would need to be synchronized as well.

View 2 Replies

How To Query From One Column Then Sort Using Another Column

I am trying to get the last 100 albums I entered into my database using the album_id (Highest being the latest entry) then sort them alphabetically using the album_title column.

I can get the latest 100 easily but cannot figure out how to also sort the results by the album_title before I display them.

This is what I have so far which gets what I want but not in alphabetical order.

$sqlquery = mysql_query("SELECT * FROM albums ORDER BY album_id desc limit 100", $db);

while ($result = mysql_fetch_row($sqlquery))
echo "<a href='music_info.php?album_id=$result[0]'><span style='text-decoration: none'>$result[1]</span><br></a>";

I have been trying to add a second ORDER BY to the query like so.

$sqlquery = mysql_query("SELECT * FROM albums ORDER BY album_id desc limit 100 ORDER BY album_title", $db);

but this obviously isn't the way I should be doing it.

View 1 Replies

Adding Column

Let's say that I extract some data results from the database and I want to display it such as the following:

ColumnA ColumnB
Result X| Result A |
Result Y| Result B |
| Result C |
Result Z | Result D|

All results come from the same row , just dispatch in several columns.
If I have a variable saying that each result value is ' 1 '.

How do I add column A and display a total (in this case 3)?
How do I add column B and display a total (in this case 4)?

I have to precise that I don't know in advance how many results I 'll collect from the database. The ideal is to post total amount in each column.

View 2 Replies

Finding Last Row In Column And Adding 1 To It

I have a table with 4 columns, one of which is an ID column. Each row has to have a unique ID, so I was thinking that I could tell PHP to find the last row in "id", and Add 1 to it, and insert this onto the next row - that way it remains unique.

View 4 Replies

Adding Update Column?

I want to add a column with a link to update an entry, which would pass the id and all pertinent info to another form/script to change the info.

I know how to write the second part, but I can't figure out how to add the column to my output. There's not a database entry for it, so when I build my table it just makes columns for each database entry. Here's the code I use to build the table: Code:

View 7 Replies

Adding A Column To Web Page

I have a Web Page with a Form on it. How/where can I add a left hand column that will run all the way down the left side? Here is the page code, and I've attached an image of what it looks like now. Code:

<?php global $account;?>

<link href="../style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<link href="../style.css" rel="stylesheet" type="text/css" /><style type="text/css"></style>

<table cellpadding="0" width="770" height="100%" cellspacing="0" bgcolor="#FFFFFF" style="border-right: solid 1px #6b6b6b">

View 1 Replies

Adding Durations From A Column?

i have a database with a table called "songs". "songs" has 2 columns "track title" and "track duration". I am having trouble with getting the summed total for the track durations column which is "type time". ive read the thread HERE about this topic but i cant figure out how to do this when using the entire contents of a table column.

View 1 Replies

Copyrights 2005-15, All rights reserved