Adding Values In One Column From Query Results

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?


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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

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 View Related

Compare The Column Values And Show The Values Those Are Not Equal To 'NA'

I have table which contains lots of columns. I just want to show the values which are actually filled up that means i just don't want to consider the column value where it is 'NA'.

name address phone
A NA 9999999999
C mumbai NA

So, now i want the output for first column should be look like this-


A 9999999999

It should skip the NA part. i have tried the following method

if(($name=='NA') &&  ($address=='NA') && ($phone=='NA'))
// don't do anything
}elseif (($name=='NA') &&  ($address!='NA') && ($phone!='NA'))


i have more than 30 columns. so how can i check each and every column like this??

show only those values which are not equal to 'NA'?

View 8 Replies View Related

Having Trouble In Adding 1 To A Database Column

I am making a voting poll. The trouble is that I can't make the database add 1 to the column that has been selected.

View 2 Replies View Related

Adding A New Column To An Existing Database

I've created a table and populated it with test data, but now I've realised that I need a new column. Is there anyway to add in a new column, or do I need to create a whole new database? I'm using phpmyadmin.

View 8 Replies View Related

Adding Dummy Column In Kohana ORM?

I want to add dummy column in kohana ORM .I have a field of type longtext . I want to have a new field which contains it's strlen.

View 1 Replies View Related

Adding A Value To An Existing Value In Mysql Column?

I'm making a system similar to the like system in facebook. THis is what I got:

$insertlike = "UPDATE status SET likes='$username' WHERE statusid='$statusid'";

And that works fine. But when another user likes the same post he replaces the previous user who like the post. Is there anyway I can add his username to the already added username?

View 3 Replies View Related

Adding An Entire Column In A MYSQL Table

I run a site where members submit photos and get points based on the photos they submit. I'd like to get their total points, but I'm at a loss on how to do that.

I have a mysql table set up with every photo that includes title, description, the user who submitted it, and the number of points that picture is worth.

I'd like to write a query that goes through that table, and whenever the 'user' column matched the user, it added up the points in that row. It sounds easy, but for the love of me, I can't figure out the mysql commands to make it work. Any help at all would be awesome.

View 1 Replies View Related

Magento - Adding A New Column To Sales_flat_quote_item And Sales_flat_order_item?

I'm working with Magento version, and I want to save a value in sales_flat_quote_item table (and pass it to sales_flat_order_item). I've found this tutorial, but I'm not sure if it's still relevant (to Magento version since it talks about a table called sales_order, which I believe is now sales_flat_order and looks a bit different.

Should this method still work? If so - Can I use it for sales_flat_quote_item and sales_flat_order_item and what entity_type_id should I put in the commend


View 1 Replies View Related

Updating MySQL Column By Adding Rather 'replacing'

as the summary already says, - I want to update a certain column on my MySQL database with a certain number that needs to be added to the already existing value in the column, rather replaced in the column.

mysql_query("UPDATE dice SET points='$calcdb' WHERE user='$_SESSION[usersession]'"); 

Variable $calcdb refers to a number that was scored by a tossed cube divided by hundred (if that's important), therefore the points can't be replaced.

View 4 Replies View Related

Update Count Column By Adding 1 It Always Adds 2 Instead?

I have a MySQL table with 3 fields; infoid (auto Increment), advertiser (varchar 100), and count (int 11). When I try to update my count column by adding 1 it always adds 2 instead. Can someone explain to me why this is? It seems like it should be a simple process but it is starting to drive me wacky. My simple script is below.

$category = "attractions";
$advertiser = "cvb";
if(!empty($category) || !empty($field)){
$query="UPDATE $category SET count=count+1 WHERE advertiser = '$advertiser'";
$result = mysql_query($query) or die ("didn't query");

View 2 Replies View Related

Update Views After Adding A Column To A Table?

In cakephp, after you add a column to a table that's in a model, is there a way to automatically update all the views that are based off of that model?

View 1 Replies View Related

Combining Multiple Csv Files Together And Also Adding A Column During Concatenation?

I have a set of files I am trying to import into mySql.

Each csv file looks like this:



This is a server box so I wont be able to compile anything but if you give me a Java solution I will definitely try to run it on the box.

View 5 Replies View Related

Magento Adding Left Column In Home Page

In my magento project left side of the Home page is empty, i want to place an image in left side and also in the middle portion, what are the steps to place these two in my project?

View 1 Replies View Related

Change The Value Of Status Column When Adding A Friend With Doctrine?

I'm starting now with Doctrine 2 and Zend Framework, and I'm creating a system of friendship among the users. In the table Friends of my database, I have the following columns:

User_id | Friend_id | Status

Where status is a number that can be -1, 0 or 1.

I'm using the relationship many-to-many, more specifically, the same shown in the documentation of Doctrine: [URL]

But I (unfortunately) do not know how to modify the value of status column of the table friends.

EDIT: The status column is inside the friends table, and not in the users table.

View 3 Replies View Related

Results On Multiple Pages: Storing Search Results Or Query Again

Suppose I have a search result with different pages. I could store the results and get them out of the database with a simpler query for the next page. Or I could query again and display only a portion of the results (eg from 20-30). What would be the most efficient. How would bulletin boards do this, or google?

View 2 Replies View Related

Copyrights 2005-15, All rights reserved