Adding Values In One Column From Query Results

Nov 27, 2001

I have this query:

SELECT *,
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?

ADVERTISEMENT

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

Sep 23, 2010

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

Oct 13, 2006

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

Apr 29, 2011

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)

[code]....

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?

Apr 23, 2009

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.

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

[Code]....

View 3 Replies View Related

Displaying SQL Query Results In 3 Column Table

Jul 3, 2007

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

Nov 2, 2007

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

Jun 20, 2010

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?

Sep 10, 2008

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?

Aug 11, 2009

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:

<?php
$search=$_REQUEST["sm"];
$pieces = explode(",", $search);

[cod]...

View 3 Replies View Related

Adding A Delete Button To Query Results?

May 26, 2010

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:

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

[Code]....

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?

Apr 20, 2011

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:

[Code]....

View 2 Replies View Related

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

Apr 12, 2010

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?

Feb 18, 2011

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 />";
code....

View 1 Replies View Related

Display Db Query Results Based On Values From An Array?

Feb 2, 2010

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>";

[code]...

View 3 Replies View Related

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

May 22, 2011

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?

Jul 5, 2011

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:

1
2
3
John
Steven
Patrick
http:[url]...
http:[url]...
http:[url]....

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?

Jun 5, 2010

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?

Aug 12, 2010

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?

Mar 1, 2011

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

Jun 9, 2005

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.

<?php
$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

Oct 7, 2003

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

Jan 30, 2000

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?

May 24, 2007

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

Aug 15, 2007

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?

Dec 27, 2010

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'

Sep 7, 2009

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
B NA NA
C mumbai NA

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

Quote:

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'))
{

[Code]....

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

Aug 8, 2003

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

Feb 21, 2010

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?

Apr 14, 2011

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?

Jun 25, 2010

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

Mar 8, 2006

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?

Dec 7, 2010

I'm working with Magento version 1.4.1.1, 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 1.4.1.1) 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

[Code]...

View 1 Replies View Related

Updating MySQL Column By Adding Rather 'replacing'

Dec 31, 2010

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?

Mar 12, 2009

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.

<?php
require_once('emin.php');
$category = "attractions";
$advertiser = "cvb";
if(!empty($category) || !empty($field)){
$query="UPDATE $category SET count=count+1 WHERE advertiser = '$advertiser'";
mysql_query($query);
$result = mysql_query($query) or die ("didn't query");
}
?>

View 2 Replies View Related

Update Views After Adding A Column To A Table?

Jan 21, 2011

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?

Feb 21, 2011

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

Each csv file looks like this:

Header1;Header2;Header3;Header4;Header5
Data1;Data2;Data3;Data4;Data5;
Data1;Data2;Data3;Data4;Data5;
Data1;Data2;Data3;Data4;Data5;
Data1;Data2;Data3;Data4;Data5;

[Code]....

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

Sep 25, 2009

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?

Apr 15, 2011

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

Nov 15, 2005

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

Ordering Mysql Query Results - Calculate Results And Order?

Jul 11, 2010

i have two tables called teams and results and basically the the results table will store the results of each match the team has. what i need to do is when i select all the teams i need the team with the most results to be ordered first and descending from there.

------------------
man united   12 pts
liverpool       9 pts
etc etc
------------------

the tables im using are below if anyone could tell me the best way of calculating the results and ordering them

[code]...

View 8 Replies View Related

Sort Results By Another Column

Sep 29, 2007

A script lets users search a database for 'last name' and displays those results

what is the simplest way to let them sort those (further query) results by 'first name' ?

View 7 Replies View Related

Loop Column After 2 Results?

Dec 25, 2009

Here is what I have:

Client ID             Company name               Client ID                Company name

I then need a script to echo 2 results per row then start a new row.

I've tried many things, but never could get a second row to appear.  Each row will have 4 columns.

Here is my code without the "guts"  My vars will be $id and $company. 

$result = mysql_query("SELECT * FROM client");
if(mysql_num_rows($result) < 1)
{
$results = 'You have 0 clients.';
}

[Code]....

View 4 Replies View Related

How Do You Sort Your MySQL Results According To Column Name?

Jan 5, 2007

I normally output the results of a mysql query according to ID. I display the results in tables. Code:

View 10 Replies View Related

Get Results From One Column Which Has A Character Limit Of 200?

Jun 29, 2011

Im making a (small) site in php & mysql. The mysql database consists of a single table with possibly tens of thousands of rows (in the future). I only need to get results from one column which has a character limit of 200. Considering that I don't want any stopwords or "common" word features; and the column contains filenames (some with special characters), what type of search would you recommend?

EDIT: Just some more clarification on filenames: I don't want to do an exact match; say I have a name like this: [abc]_random_file.txt; searching for "abc random" OR "[abc] random" OR "abc txt" should all match. Hope that makes sense.

I've considered:

1----SQL like statement
2----SQL regexps (as shown on this website: [URL])
3----Mysql Full-Text Search(MyISAM)
4----Third party search engines

With #2 I can probably get the results I want, however I don't think it would work well with my table if it gets big?

View 3 Replies View Related

ADVERTISEMENT