Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





ORDERING BY My Calculation


Is there any way I can ORDER BY $sum so that the smallest one is shown first, the problem is because the sum comes after the SELECT statement. This is a simplified version to my much larger problem. PHP Code:

$maths = "SELECT * FROM maths";
$mathsResults = mysql_query($maths);
while ($mathsRow = mysql_fetch_array ($mathsResults)){
$int1 = $mathsRow["int1"];
$int2 = $mathsRow["int2"];
$sum=$int1+$int2;
echo $sum;
}




View Complete Forum Thread with Replies

Related Forum Messages:
Ordering And Re-ordering My Dynamic Navigation Menu
I am attempting to develop a couple of functions that will allow me organize and re-organize my navigation menu after I edit or add a new page to my website using my CMS.

Has anyone successfully done somthing like this before? if so please share your method.
What I have below works for the most part, but I am looking to make things work better.

* note* Throughout the code you will find the 'title_level' varable and column title, this will hold a number 1 to however many results are in the database and is used to place in order each link/button in the navigation. Code:

View Replies !
Ordering By ASC
I am having trouble ordering by ASC.

I made a tagbox, and when it loads up it takes you to the bottom of the page, and it should show the newest comment first, but it doesn't. It shows the first 25 tags then stops...

mysql_query("SELECT * FROM {table} ORDER BY id ASC LIMIT 25");

View Replies !
Ordering From DB
If I have a db for an auction site and I want to display the auctions closing soonest, how do I do this? I know how to code it, just the theory behind it?

View Replies !
AVG Calculation
how to times my AVG answer by 10, my AVG shows and answer of 5 and i want it to show 50 representing the percentage, Also how would i show this as a percentage not a normal number.

View Replies !
Calculation
I'm creating an order form whereby result is displayed in the next page.

<input type="radio" name="gift" value="toy A"/>
<input type="radio" name="gift" value="toy B"/>
<input type="radio" name="gift" value="toy C"/>

They cost $5, $10 and $15 respectively.

<input type="checkbox" name="extras[]" value="Ribbon" />
<input type="checkbox" name="extras[]" value="Card" />
<input type="checkbox" name="extras[]" value="Wrapper" />
<input type="checkbox" name="extras[]" value="Box" />

Additional $1 for each of the extras checked.

How can I know which toy is chosen, which extras are selected and total up the cost? I just need to display the final total cost.

View Replies !
Sql Calculation
I just started using php and mysql for the past 1 month and slowly picking things up: i got a question on DB calculation. Pls refer the table below:

account number ¦ payment
-----------------------------
45621 ¦ $100.00
45621 ¦ $50.00
42000 ¦ $70.00
42000 ¦ $20.00
42000 ¦ $30.00
45656 ¦ $95.00

For the account number, notice that there is duplicate account number with different payment value. Now, how do I calculate the total value for each account ie: for 45621 = $ 150.00 and 42000 = $120.00.

View Replies !
Ordering Before Grouping
In my particular database table, I have many rows which its common element is the `username`, now the most unique and method I wish to order on, is `time` (timestamp). In my code my base query currently is:

SELECT `username` FROM `download_counter` GROUP BY `username` ASC

Which then as expected, on page rows are ordered by username in alphabetical order. What I wish to do is, on page view, rows are ordered by the `time` value. However heres my two problems:

For starters it probably comes to no surprize that when using GROUP BY, the query remembers the first row it comes across and ignores the laters, so if there are three rows, oviously the first one it finds is the earliest of times, which is exact opposite of what I want. My other problem involves my attempt at a query:

SELECT `username` FROM `download_counter` ORDER BY `time` DESC GROUP BY `username`

this brings back:
#1064 - You have an error in your SQL syntax ... near 'GROUP BY `username`

I guess a ORDER cannot be before a GROUP.

But then what do I do? Is there a way maybe to query all results, then after that preform a GROUP?

View Replies !
Columnar Ordering
lets say i got a table with 2 columns on my database. one column is a unique_id set to auto increment, and the other (we'll call "name") contains:

andy
anne
bob
carry
cj
paul
pete
saul

i've figured out how to print that stuff in a while loop into two column in html like:
PHP Code:

View Replies !
Ordering From A MySQL DB
I have a MySQL database that has 400 entries in it, What i want to do is extract these from the database. say I want to extract all the people whos name starts with the letter "C" ...Im not sure of the query for that?

View Replies !
Ordering Numbers.
Say I'm selecting a few numbers from a database...

Example:
12, 80, 100.

// MYSQL
SELECT number FROM db.numbers ORDER BY number ASC;

Results:
100, 12, 80.

How can I get these numbers to display in the proper numerical order: 12, 80, 100?

View Replies !
Ordering An Array
How is the best way to order an array in asc and desc order?

View Replies !
Ordering Range()
how to reverse the order in following script? PHP Code:

View Replies !
Ordering By Date
$query = "SELECT eventid, name, DATE_FORMAT(date, '%d %b %y') AS date, time, type, extra FROM events WHERE type = 'Training' AND date BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 21 DAY) ORDER BY 'date' desc";

This displays any events within the next 21 days, but not quite in the right order!

The outputted result is:
25 Mar 07
24 Mar 07
08 Apr 07
07 Apr 07
06 Apr 07

As you can see the months are in the correct order but how can the days be reversed? eg:
24 Mar 07
25 Mar 07
06 Apr 07
07 Apr 07
08 Apr 07

View Replies !
Ordering Rows By Value
Is it possible to display rows in order of a value within the rows? I need to do this without saying 'order by' in the 'select from' statement. The reason is because i'm using values from my select from statement to work out totals.

Once i've worked out the totals i'm displaying the rows as per the code below. This works fine but I want to display the row containing the smallest $TOTAL_REDUCED value first, with the next highest next, and so on. Code:

View Replies !
Ordering Lists
I have developed a script (with help) that tries to order events stored in my .txt file by date. The .txt file looks like this: 1st|Jan|Meeting at House| 15th|Feb|Meeting at your House etc

The script orders the dates from lowest to highest but does not order dates before the 10th. Apparently 1st - 9th comes after 31st.. Code:

View Replies !
Ordering SQL Results
How do I order my sql results in descending order?  This is my query:
mysql_query("SELECT * FROM members order by uid limit 1 descending");

View Replies !
Ordering By Last Name When The Field Is Name
I'm trying to run an ORDER BY addition to my query to do it by last nights, not first name, but I have name as a single field.  Any ideas?

View Replies !
Module Ordering
I am working on a CODE script - the idea behind it is that a user is able to choose which modules he wants to display on his page. When I say a module all I mean is a block of code which is in a seperate CODE file (for example: news.php, weather.php, search.php etc).

I have two tables. The first table is called 'modules' and simply contains a list of all the modules. It has ID, status, name, description and filename columns. The filename column is the path to the modules CODE file. Code:

View Replies !
Ordering The Database
i have a download center in my website . the code that calls the files with ID order is

<?
@$aepublic->DBQuery("SELECT * FROM multimedia where homepage =1 ORDER BY ID");
while ($aepublic->DBGetRow())
{
//$filename=$aepublic->access["file"];

?>

it now start from the lower ID to the higher one. example:

if a file has an ID "10" & another has an ID "11" . he will get the file with the "10" first . i need to get the file with the "11" so that the most recent one is in the top .

View Replies !
Ordering Records
I have a table of carpet designs, with references like Chinese 1, Chinese 2, Chinese 3 etc. As these are text fields, they display in the order Chinese 1, Chinese 10, Chinese 11,... Chinese 2, etc. I need to have then as Chinese 1, Chinese 2, Chinese 3 etc.

I was about to add in an extra field RefNo that would be an integer and just be the numeric part of the text ref, and would never be displayed but just be used to order the records. Which I presume will be fine, but just wondered if there was any way of doing it just with the existing field?

View Replies !
Ordering Models
I am trying to allow the models in a mysql database to be ordered by the site owner. I was thinking along the lines of a <SELECT> list containing the model names and Up and Down buttons to move the models up and down the list. I am unable to come up with a solution for getting the order from the list however.

View Replies !
Date Ordering
I've got this news archive news page and at the moment the news is listed as below:

18 March 2004

News Item 1
News Item 2

17 March 2004

News Item 1
News Item 2

An so forth, but I was wondering how do I go about re-ordering the news archive page whereby I have the following format Code:

View Replies !
Ordering The Output
is there a way to change the order in which the db is queried and outputed. i have a really basic news page but it displays the articles in reverse order can some one help me out with this? Code:

View Replies !
Ordering By Letters
Is there a way to, say, have a Member's List, however, make it ordered by a certain method, though, making it so it only display a certain character at the start or something. Um, what I mean is posting every user's name, however, sorting it by a certain letter. So, on a page, if I want it to display names that only start with c, it displays all names that start with c.

View Replies !
Ordering Results
I've created a basic news posting script but I'm having trouble out putting the data from the SQL database in the way that I want to. Basically there are two fields in the news table that I want to use to order the results which are output to the browser.

they are "hits" (which is the total amount of times that the record has been viewed) and "date" (which is fairly straight forward!). I want to output the results so that the records are shown in date order but the results within each date are ordered by the number of hits.

View Replies !
Ordering By Mean In MySQL
I have a star rating system on my site and would like to show users the top 10 most highly rated items. The table of of star rating data consists of an id (star_rating_id), the item (star_rating_item), the total score (star_rating_score) and the total number of votes (star_rating_votes).

In order to rank the results I wish to calculate the mean score (ie. star_rating_score / star_rating_votes) and then order the results by this mean in descending order. Code:

View Replies !
Product Ordering
I need to setup a product ordering system. Currently I have a column in my products table which is called products_order. There is a number there and when I list my products (according to which category the product is in) it lists it ORDERED by the products_order column. I need to setup an easy way to edit the listing though and I was curious what the most logical way to do this would be. I need it to be simple enough so that anyone can do it.

View Replies !
Ordering Values From The Same Row?
I have a database where each user has a row, and aswell as username, password etc. the fields count how many times each user clicks on a certain link. For example, a sample row might look like this: Code:

View Replies !
Ordering By Month
I need to create a list of months to act as links. There will be a number of events in a database each with a date (example: 2oo6-1o-1o). If there is at least one event in a given month I want to display the month's name (October) but only once, i.e. if I have 15 events in October I only want October to appear once as a link.

View Replies !
Ordering By Popularity
I have a fairly large mySQL database to individual text files (guitar tabs). I want to order a top 10 list of the files by popularity in my php document. Currently i simply order my list by the number of views per file.

This is not satisfactory as newer files are typically going to have been viewed less that older files that have been there forever.

How would this best be done. Surely it would be inefficient to process each database entry (views / time_since_posted). Is there a better way to do this. Any Ideas?

View Replies !
Date Calculation In PHP
Hi!

I'm trying to get a date with PHP i.e. 14 days from now in yyyy-mm-dd or any other format like print (date("Y-m-d")) + 14 days.

Is there an easy way to do this??

View Replies !
Binary Calculation
I need some way of determining which bits are set in a binary number.

eg.

Decimal Number: 40
Binary Number: 00101000

How can I determine that the binary equivalent of 8 and 32 are set??

View Replies !
Duration Calculation
I had a look at a post here in regards to this issue but after it i was blank. I gave it a shot and i got a wrong value.

View Replies !
Time Calculation With Php
users of my web site enter time and distance of a run the did into a http-form. the data will be processed by a php-script and stored in an mysql-database. what i want to do is to calculate from the data what time they needed for a 1k-run -> i.e.: if one runs 12k in one hour it will be 5 minutes for 1k.

the problem is, the data from the textfield of the form comes in as a string and hence i just can't divide the data ride away.

time input should look like: 1:00:00
distance input should look like: 12
and output should look like: 0:05:00

any ideas?

View Replies !
PHP Math Calculation
I am trying to perform a simple calculation from variables passed from a form. The code is as follows:

<?php
echo "Bonus for the year: <b>";
$x = (($awage * $nibt) + ($awage * $ratio));
$x = number_format($x, 2);
print $x;
echo "</b><p>";
$xtmp = ($x + $qtr);
print $xtmp;?>

The calculation multiplies two different values (based on values from the previous page), and then sets it equal to $x. The first calculation prints fine, but when I try to add it to $qtr (also passed via radio button from previous page), it doesn't calculate correctly.

I found that if I hard-code the values for $x and $qtr after I print $x, then it will calculate correctly. I am thinking that I am using the variables incorrectly somewhere.

View Replies !
Leave Calculation
for example, for the first 2 years, he does not has bonus leave, on the third year onwards, he has 1 day increase. by default, he has 18 days leave, on the third year, he can carry forward the 10 days from the previous year, now, he has 28 days leave plus 1 day bonus leave = 29 days. same with the fourth year, he can carry forward 10 days, so, he has 39 days leave plus 1 day bonus leave = 40 days.

if he apply 2 days leave in the first 2 years, the balance is 16 days. on the third year, he only can carry forward 10 days only, not 16 days. if he apply 12 days leave in the first 2 years, the balance is 6 days. on the third year, he only can carry forward 6 days only, not 10 days. this is the problem that u don't know how to fix, can you teach me?

View Replies !
Time Calculation
does anyone know how to calculate time difference between 2 periods of time(say 12:00 am and 1:00am) ?? i have been trying to come up with an algorithm but bugs keep crawling in.


View Replies !
Date Calculation
I would like to make a selection from the database in the following manner ie which is created in the last 1 week or last 2 weeks. There is one field named created_date in the database and the date is in the format yyyy-mm-dd. I have seen date calculations based on month and year but didn't see one on a week basis.

View Replies !
Days Calculation
i can't seem to get this what im trying to do is work out the elapsed time in DAYS from 2 dates code is:

             $time_now = time();
             $d2 = date('Y-m-d H:i:s', $time_now);
             $d1 = date('Y-m-d H:i:s', strtotime($ng_date));
             $days = ceil(($d1 - $d2) / (60 * 60 * 24));
when echoing out it produces:

2007-06-02 16:53:24
2007-08-27 18:00:51
which is right, but $days echoes out as 0.

View Replies !
Add Trailing Zero To Calculation
I am pulling a couple of numbers from a database (productcost and productprice).  I am trying to subtract the cost from the price to calculate the profit of the item.  I have this part working with no problem. My problem lies when the final number has a trailing zero it will drop that number (i.e. 1.2 as opposed to 1.20)

Here is what I am using:

$profit = $row_viewcoils['ProductPrice'] - $row_viewcoils['ProductCost'];
      echo $profit;

View Replies !
Calculation Form
I need to build a calculation form.. basically they click a couple radio buttons from features they want and then the user enter's in the number of words of the document and then they hit "calculate" button and it gives them an estimate for a quote. Need a little help with the structure of the form, anyone shed some light?

View Replies !
Percentage Calculation In Php
i have the following calculation code that adds the $total and the $tax variables..

number_format($total+$tax,2,'.','')

how i can calculate the total and then subtract 15% of the final value.

View Replies !
Calculation In A Query?
Is it possible to do something like this:

UPDATE `Members` SET `hungerlevel` = (hungerlevel - 1)

Im trying to run a query that updates all users in my member table and it takes 1 off their hungerlevel. I could do a while loop i suppose... i was just wondering if there was a way to do it this way.

View Replies !
Database Calculation
for example i rent a space for stock keeping and i can get 1% of total prices per day. I had created a database to record all in/out stock per day as:

[date] [status] [quantities] [unit_price]
2007-09-16 'IN' 1000 3.50
2007-09-16 'OUT' 100 3.51
2007-09-17 'IN' 500 3.40
2007-09-18 'IN' 1000 3.35

Sorry for my dumb, i'm stuck on a database calculation above. i hope any expert can show me how to get income calculation between $date1 and $date2 through sql query?

View Replies !
PHP/HTML Calculation
I am making a little Purchase order entry form for a mysql database. I have the form and can submit everything just fine, Only thing is I can't seem to figure out how to make a calculation on various text boxes.

I need to make a sum of a group of boxes, calculate taxes etc... Anyone able to point me to some sample code of a way to make arthimatic functions on the contnts of box1 and box 2 and put them in box 3. I will only be inserting box 3 into the database and that part works already.

View Replies !
Shipping Calculation
I've got to add another condition to my shipping calculation - right now it reads:

if ($total > 81.75)
{printf ("%01.2f", $total * .11);}
else {echo "8.99 ";}

The condition I need to add needs to accomodate International shipping - $total * .25. I have a field for '$shipcountry' - the new condition needs to identify whether the order is being shipping with USA or goes to another country... : something like....

IF $shipcountry = "USA",
THEN DO USE CODE ABOVE
ELSE $total * .25

It looks like a couple of IFs AND then ELSE to me...just wish I knew how to write it.

View Replies !
Array For A Calculation
I am currently using a an array to perform a calculation similar to

http://www.webmasterworld.com/forum88/7085.htm.

[example]
$nearest_distance = array();
$findLocations = mysql_query("SELECT latitude, longitude FROM locations");
while ($loop_findLocations = mysql_fetch_array($findLocations)) {
$latitude = $loop_findLocations["latitude"];
$longitude = $loop_findLocations["longitude"];
$yarddistance = distance($latitude, $longitude, $cutomerlat, $cutomerlong, "m");
$nearest_distance[] = $yarddistance;
}
sort($nearest_distance);
print_r($nearest_distance); // print array
echo '<br> Best Yard:'. $nearest_distance[0];

View Replies !
Calculation With Month...
I create some search option with drop down list box. search by month is 1 of them. I've a table named orders, suppose LabOrder_No & Log_date. dates are storing in database as yy-mm-dd but im retriving as dd-mm-yy.

I will select a month name from list (jan,feb....dec & their values are 01,02...12), click submit button & display the total orders & quantity of that month. to collect total quantity, i wrote a function: Code:

View Replies !
Calculation Of Items
I was just wondering what method is best to use to calculate items from a drop down menu. I have two lots of drop down menu of which i want to send to a page to clarification before being submitted.

View Replies !
Days Ago Calculation?
<?php
$month = 10;
$day = 17;
$year = 2006;

$days = (mktime(0, 0, 0, date("m"), date("d"), date("Y")) - mktime(0, 0, 0, $month, $day, $year)) / 86400;
echo $days;
?>

-> Take the seconds from unixtime now, minus unixtime date, split by seconds in a day = amount of days ago Problem is, the output is: Code:

View Replies !
Calculation Problem
im working out a users age, by deducting the year they were born from this year 2007

so i'm born on 1979, todays year is 2007

2007 - 1979 leaves 28

but the code shows as -28 instead of just 28, i tried a str_replace but no joy

  ## Year calculation
  $profileyear = $yearborn - $thisyear;
 
  ## Get rid of the - sign
  str_replace("-"," ", $profileyear);

can anyone tell me what i did wrong?

View Replies !
Ordering Users In Table
I've got this code which displays the users which display this in a table order by user:

<table cellpadding="2" cellspacing="2" border="1" width="100%">
<tr>
<td><b>Position</b></td>
<td align="center"><b>User</b></td>
<td align="center"><b>Correct Answers</b></td>
<td align="center"><b>Percentage</b></td>
</tr>
<?

$result=mysql_query("select count(*)
FROM quiz_questions,quiz_category
where quiz_questions.qzid=$qzid
AND quiz_questions.catid=quiz_category.catid");
list($quest_count)=mysql_fetch_row($result);

$result=mysql_query("select quiz_input.fuid,fname,surname,count(*)
from quiz_input,quiz_answer,quiz_questions,users
where quiz_questions.qzid=$qzid
and quiz_input.qsid=quiz_answer.qsid
and quiz_input.qsid=quiz_questions.qsid
and quiz_input.qaid=quiz_answer.qaid
and correct='yes'
and users.fuid=quiz_input.fuid
group by fuid order by 2 LIMIT 10");

$i=0;
while (list($DBfuid,$DBfname,$DBsurname,$DBcount)=mysql_fetch_row($result))
{
$i++;
echo "<tr><td>$i</td><td align=center>$DBfname" ." ". "$DBsurname</td><td align=center>$DBcount</td>";
$percent=round(($DBcount*100)/($quest_count));
echo "<td align=center>$percent" . "%". "</td></tr>";
}

?>
</table>
What would be the best possible way to achieve 1==,1==,2,3,4==,4== etc??
Would be best idea to compare one row at a time??


View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved