Adding Values In One Column From Query Results
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?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
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!
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. <?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.
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.
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.
Adding New Values To An Array That Already Contains Values..
is it possible to append new values to an array that already has values in it?? say, i have my existing array; existing array; $array = array([66314] => 66314 , [66315] => 66315) ; then , when i check my checkbox on my next page, the ids should be appended to the $array: array that needs to be added to the $array; $array = array([66316] => 66316,[66317] => 66317,[66318] => 66318); how should it be done??
Sort Results By Another Column
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' ?
Adding Different Values
How can I do If I need to add some values, I am using LEFT Join and I am displaying some lists There is my code: PHP Code:
Adding Results.
I need to add a bunch of results coming from a DB. I tried doing a simple while statement with a plus sign, but that failed because all it's doing is echoing all the numbers =O! Code:
Adding Values To An Array
i have an array that gets filled by users hitting a FAVORITE button on 'product' pages. I can get one value, but the value doesn't stay after the page has refreshed... so i think I need to use Sessions but I have tried before and have always been unsuccessful... here is the code that displays the favorite product. PHP Code:
Adding Date To Results
I have a mysql database with links to files which output as links. I have added a Table called "Date" for the date the file was last indexed. what I want to do is add a table to output the DATE without it being included in the link. $counter = $range + 1; while($row = mysql_fetch_row($result)) { $fullURL = "ftp://".$row[2].":".$row[3]."@".$row[1].":".$row[4].$row[0]; $linkURL = htmlentities(str_replace(" ", "%20", $fullURL)); echo "$counter. <a href=$linkURL>$fullURL</a><br>"; How do I add the table to the end of the file to generate dynamically with the results?
Adding Values Onto An Associative Array...
I'm trying to develop a simple class which through the interface you can add elements to an array. The method I have used to add the elements is setContentFields($name, $field_type), I have used an array counter variable to increment the array index each time. To me this seems like a workaround, and I wondered if there was a more elegant way of doing this. The class is as follows:
Basic Question - Adding Values
I have a form that contains radio button groups. Each group is assigned a name and each radio button has a numerical value (1,2,3, etc). I want to total the values from each group and forward it to another page which displays that total. How do I use PHP to take the value from each button group and add them? I can pass each individual answer to the second page ok, I'm just having difficulty totaling those values.
Adding Sums Of Array Values
I have two arrays: ('a'=>1,'b'=>3,'c'=>2,'d'=>6) ('a'=>2,'b'=>0,'c'=>4) I need a very efficient function to add the values together for each element. For instance, the output would be an array: ('a'=>3,'b'=>3,'c'=>6,'d'=>6) This function could potentially be used in billions of iterations, so it needs to be as efficient as possible.
Adding Values To A Superglobal Array
i have a variable (well, an Object) which is needed in beneath every Script. it's not needed to be changed during the whole script, so i like to access it easyli without passing by or declare it as global in every function. afaik it isnt possible to set a variable to superglobal. Is there any reason why i shouldn't add it to the _SERVER array or any other superglobal?
Adding Dynamic Values To An Array
I am having a problem adding dynamic values to an array. The values that I want to add to the array are sent via a query string. The array is stored in a session. the variables are sent like: ?var=test1 ?var=test2 How can I send these variables to an array. I tried doing it like this: $_SESSION['varList'] = '"'.$_SESSION['varList']'",'.$var; but this only creates one entry in the array which is "test1","test2"
ODBC Results Sorting And Adding?
I need to go through ODBC results and add Quantity for like items. Quick example: Database Is: ItemQntyDate foo11-10-99 bar51-15-00 foo21-11-99 I need to somehow search through results and add matching Item Quantities together. In this example, the return I would expect is: ItemQntyDate bar51-15-00 foo31-10-99/1-11-99 because the foo Qnty added together became 3. Any thoughts on how to accomplish this? Load the ODBC results into an array and somehow sort through the array? Never done that before...
MySQL Query Returning Empty Column
Here's my code: $query_get_machine = sprintf("SELECT machines.ID, machines.NotifyID, machines.Name, notify.ID, notify.`Data` FROM machines RIGHT JOIN notify ON machines.notifyID = notify.ID WHERE machines.ID = %s", GetSQLValueString($colname_get_machine, "int")); Can anyone tell why the notify.`Data` column might be returned empty? All others display as they should.
Adding Values To An Array In A Foreach Loop.
I am creating a function for my horse site that will choose the color of the horse. I have a database full of horse breeds and all the possible colors they can be. Here is what the "color" column might hold for one of the horse breeds: solid,paint The word "solid" can be a bunch of different colors...so I am trying to make my script add all these colors to an array I am populating that holds all the possible colors for that breed. Here is my current code for the function with comments to let you know what is going on Code:
Query That Stores Column Headers From .csv File In Variables
I have not been able to figure out how to capture the column headings from a file on my web server in variables to be used in a .php script. For example. File Headers: ID, NAME, OCCUPATION, DATE I would like a script that would grab those headers in a file and store them in variables: $ID=ID $NAME=NAME $OCCUPATION=OCCUPATION $DATE=DATE
Adding Additonal Values From Forms To The Top Of The Action Page
I have form on multiple pages with one text input and two hidden fields. When the user submits the form, they are taken to: /actionpage.php?input=x&hidden1=y&hidden2=z On the action page there is a third party JavaScript that I can not change that requires the two hidden fields. I am wondering if I can setup something at the top of the action page that establishes the two hidden fields, allowing me to take them off from all my pages while still allowing the third party script to work.
MySQL Query - INSERT - Unknown Column 'test' In 'where Clause'
I have a registration script on my website, and it was working fine, I added a second MySQL INSERT query to it, for another table so I can use JOIN's later on with the second table, but I keep getting the same error: Unknown column 'test' in 'where clause' can someone see whats wrong with this? Code:
Adding SUM To Query
I have a SELECT * query that returns info such as 'name', 'date', 'cost', and 'notes'. At the head of this query return it reads how many records were found. I would like to append that with 'how many records were found at a cost of' ... But haven't been able to find a means of totalizing the 'cost' column in my query. Does anyone have any ideas on how this might be accomplished ??? I've spent considerable time on the net looking at examples and my reference book but so far, no luck.
Adding Query Strings
How do you put the strings after an url together. e.g. the url is already: http://something.com/index.php?id=2 and a link is going to change it to index.php?id=2&order=4
Adding Strings To A Query String?
I want to use my string $stringvar to show text in this sql query. ATM its sticking "$player, $score" into a field, I want it to instead print it out into the sql statement. This is my code: $stringvar="$player, $score"; $sql=mysql_query("INSERT INTO $game_db VALUES ('$new_matchid', '$opponent', '$map', $stringvar, '$result')"); This is what I want the sql query thing to look like: $sql=mysql_query("INSERT INTO $game_db VALUES ('$new_matchid', '$opponent', '$map', $player, $score, '$result')");
Navigating Database Results And Posting New Values
I am trying to dynamically display results that I retrieve from my database i.e. only 5 results per page and code should automatically compute how many pages it needs and create links for each page. I have also added a link at the top of my page so that if user wants to POST new data he can post it. Problem is that when I click on page 2 or 3 or any numbered page and click on POST link it gives me following error "CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are: And it did not tell about any header etc. Code:
Getting Too Many Results From A Query!
This is very peculiar -- for some reason, I'm getting 6-8 results from each of these queries, although only one listing matches. I have a pair of forms on one page: <FORM> Search for lastname: ____________ [Submit] </FORM> <FORM> Search for email: ________________ [Submit] </FORM> This goes to a searchresults.php page: if ($searchname !== "") { $query="SELECT artistID,firstname,lastname,email,city,state,count ry from artists WHERE lastname='$searchname'"; $result=mysql_query($query) or die(mysql_error("Could not execute query.")); while($row = mysql_fetch_array($result)) { $alt_artistID = $row['artistID']; $alt_firstname = $row['firstname']; $alt_lastname= $row['lastname']; $alt_email = $row['email']; $alt_city = $row['city']; $alt_state = $row['state']; $alt_country = $row['country']; echo "<CENTER><HR>".$alt_artistID."<BR>" .$alt_firstname." ".$alt_lastname."</A><BR>" .$alt_email."<BR>" .$alt_city.", ".$alt_state." ".$alt_country."<BR> <A HREF=delete.php?aritstID=".$alt_artistID.">DELETE THIS LISTING?</A><BR></CENTER>"; } } The second section is identical except for: if ($searchemail !== "") { $query="SELECT artistID,firstname,lastname,email,city,state,count ry from artists WHERE email='$searchemail'"; etc... } I don't understand why I would get 6-8 records when you can look at them and see that all but one clearly do not match...?
Using Query Results
Can you use a queries results only once? In this script I'm looping through a query and saving some values in an array. A little further through the script I need to use the same query for output. When I loop through nothing is echo'd to the browser. When I output a row count it shows that the correct number of records, so they must still be there.
Array Query - For Adding Alt Text To Multiple Image Upload Form
I've set up a form for uploading multiple images and I am writing the urls to a database, which is queried and outputs the images on a web page. This works fine, however, I also want to add alt/title text for each image upload but can't quite seem to get it working. I'm pretty new to PHP so my knowledge of how to use arrays is fairly limited. Code:
Getting Values From A Textarea To Use In A Sql Query
im trying to retrieve the text entered within a text area, split it into indiviual lines and use each line within a sql statement I can retrieve the values but only the 1st value is inserted within the sql statement Code:
Query Results In 2 Columns?
I'm struggling to figure out how to do this properly. I have done a mySQL query to extract a list of names, and done a mysql_num_rows to determine how many results I've gotten. I want to split the list in to two columns. I've created $percol = $mysql_num_rows/2 but I'm not quite sure how to "loop" through the first half of the list, echo </td><td> and then list the balance. Can anyone give me some guidance on how best to structure this?
Finding The Results Of A Query
I am working on a script that will query a database for a FNAME/LNAME combo. If it finds the combo, I need it to do one set of instructions. If it doesn't find it, I need it to do something else. What I can't figure out is what variable to check against. Here is what I have for the relevant part of the script: $connection = mysql_connect($hostname, $username, $password); mysql_select_db($databasename) or die ("Cannot connect to database" ..mysql_error()); $query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName') AND NAME=('$LName')"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); mysql_close($connection); I tried checking the value of $result to see if it changed depending on whether or not it found the selection. It does not. I just can't figure out what to use for: if (some expression){ perform this code } else{ do this }
Grouping Results Of Query
I'm brand new to PHP (just starting today to convert tons of ColdFusion/Access code to PHP/MySQL). There is a function in Coldfusion that I can't find an equivalent to in PHP. Here is what I am trying to do: If I have a query that results in this information: State Firstname Lastname Idaho Terry Pratchet Vermont Dan Brown Vermont Bob Smith Virginia Alice Johnson Virginia David Jones I would like to output the info like this: But all I can find in PHP is a way to loop through the query and show every row... if you are familiar with Coldfusion, what I am looking for is something similar to this: <CFOUTPUT GROUP='State'> #State#<BR> <CFOUTPUT> #Firstname# #Lastname# </CFOUTPUT> <BR> </CFOUTPUT> Is there a function that does this in PHP, or do I need to write code that watches the value of 'State' and manually takes care of things whenever it changes?
ODBC Query Results
Consider the following: <? $username = "foo"; $password = "bar"; $host = "db"; $connect = odbc_connect("$host", "$username", "$password") or die; $query = "SELECT id, name, address, city, state, comments1, comments2 FROM data.table1, data.table2 WHERE id = ô˜'"; $result = odbc_exec($connect, $query); while(odbc_fetch_row($result)){ $id = odbc_result($result, 1); $name = odbc_result($result, 2); $address = odbc_result($result, 3); $city = odbc_result($result, 4); $state = odbc_result($result, 5); $zip = odbc_result($result, 6); $comments1 = odbc_result($result, 7); $comments2 = odbc_result($result, 8); print("ID: $id<br>Name: $name<br>Address: $address<br>City: $city<br>State: $state<br>Zip: $zip<br>Comments1: $comments1<br>Comments2: $comments2<br> "); } ?> Only one record is returned from data.table1 (containing the id, name, address, city, state, & zip). However, there are multiple records returned from data.table2 (records from comments1 & comments2). What is happening is that when I run this script, all of the data returned from data.table1 is printed over & over again along with each record returned from data.table2. How can I make it such that id, name, address, city, state & zip are only printed once - and allow comments1 & comments2 to be printed multiple times for each occurance in the database? I've thought about just creating a second database query for the records in data.table2, however I need the join I'm getting by using the existing query. For what it's worth, I'm connecting to a DB2 database using PHP / Apache on Linux. I'm confused by this.
Losing Query Results!
If I make a query; $result = mysql_query($theQuery, $db); and then make use of the query results like so; while ($row = mysql_fetch_row($result)) { //do something with query results} I can't use $result again, I have to make another query! Why is this and is there any way around it?
Multiple Sql Query Results
I'm trying to do a query from 2 databases. Basically i have catagories within 2 databases. If both catagories return 0 rows then it does nothing but if one or both have rows returned then i need it to echo a result. I guess where i'm wondering if there's an OR statement i can use or something to that effect... something like if($numrows == 0 OR $numrows2 == 0) { echo (''); }else{ echo ('$result');
SQL Query - Results From Another PHP Page ?
Can I store this PHP code in another page, then refernece it on multiple pages using Require or Include ??? //results from sql query for ($i=0; $i<$number; $i++) { $ID = mysql_result($result,$i,"ID"); $CompanyName = mysql_result($result,$i,"1"); $ContactName = mysql_result($result,$i,"2"); $Phone = mysql_result($result,$i,"3"); $HomePhone = mysql_result($result,$i,"4"); $MobilePhone = mysql_result($result,$i,"5"); $AltPhone = mysql_result($result,$i,"6"); $SecondContact = mysql_result($result,$i,"7"); $SecondPhone = mysql_result($result,$i,"8"); $ThirdContact = mysql_result($result,$i,"9"); $ThirdPhone = mysql_result($result,$i,"10"); $Notes = mysql_result($result,$i,"11")
Sql Query Results And Scrolling
I make a mySQL database query and display the first 10 results. Then the user can click on "next" link to get the next 10 results. How can I do that without issuing the sql query again? Can I keep the results from the first query?
Query In PHP Won't Return Results In There's Only 1
$sql = 'SELECT `PageTitle` ' $sql .= 'FROM `Pages` ' $sql .= 'WHERE `PageID` = 1 LIMIT 0, 30' I have run this query in MySQL control panel and it works perfectly. When I try to do it via PHP I get no results. If I select all rows (i.e I don't specify a "WHERE") I get one fewer rows returned than there actually are.
Tabulating Sql Query Results
I'm trying to number my rows in the column named "Pos" but so far I not getting any success, someone please bail me out find below my script, this script displays my results fine but without my Positions (Pos); Code:
Combining Query Results
I have two queries which searches for any fixtures your clan (team) is in and then returns some information about the fixtures. Is there any way of combining these results and ordering them by date? Code:
Filtering Results With Php Query
This code works, but I don't know how to filter the results to where only one person is displayed..it displays all records with similar address or state or city, I would like to know how to make it display only one person when multiple search fields are entered. I'm using PHP5, and I have searched the forums but I'm not sure exactly if I found what I'm looking for...I don't know much about php or mysql. Code:
Capturing/using Results Of Query
I would like to display/capture/use the URL's that are displayed on a web page after making a query to a forum. What do I mean? I am part of a forum that uses vBulletin. One option is to display the forum topics that have had posts that day, i.e. active topics. Essentially, when you click on the link: http://www.somedomain.com/forum/search.php?do=getdaily the resultant page has a list of the active topics, highlighted as links. What i would like to do is capture/access that resultant page and use regular expressions to grab the URLs. I can do the RegEx but I cannot seem to capture that resultant page.
How Do I Show Results Of A Query
I know how to connect to a Mysql table. I want to run the query and show the results on my page. I'll have about 25 different fields I need to show on the page. Most of this information will be a couple of addresses. Basically, a billing and then a shipping address. Can someone show me how to show some of this on a page? I'll need to align all this stuff around the page.
Filter Results Of Query
I am modifying some pages in CRE Loaded. allprods.php list all currently active products and I added a manufacturers column that displays who makes that product. I want to allow shoppers to filter the product list so that it shows only products from a particular manufacturer. I have gone through several scenarios in my mind, but nothing I've thought of seems simple and bullet proof. One of the issues is that the all products query includes all manufacturers. If I were to put a variable in the query to select only a particular manufacturer, how would I code it so it does not interfere with the all products query? Would logic based upon the value of a form action work? If form action exists, someone wants to filter. If not form action or form action = all, then they want the whole list. Seems like filtering a list is pretty common and there should be an easy solution.
Query From Db, Add Values In Dropdown Menu
i wanted to query my db, and then add values to drop down menu, where when they select what they want in the dropdown, it will bring them to another page accounts.php where they will have more options.
Formatting Problem With Query Results
I have a minor problem with a script. I have written a piece of code (do...while loop) that will return results of a query a row at a time, with the proper formatting in a table. Everything works fine when there are results to lay out in the table. The problem arises when the query yields no results. When this happens, the loop below iterates once (without data) instead of not executing at all: $result2=mysql_query("select * from ...) or die(""); $myrow2=mysql_fetch_array($result2); do { ...bunch of stuff... } while($myrow2 = mysql_fetch_array($result2)); Where do we go from here?
|