If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Math in query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-30-09, 09:11
Muiter Muiter is offline
Registered User
 
Join Date: Dec 2008
Location: Netherlands
Posts: 56
Math in query

Is it possible to convert this code to I can use in my query?

Code:
$totaal = 0;
        while ($row = mysql_fetch_array($res))
        {	    
           $gewicht = ($row["p_lengte"] * $row["p_breedte"] * $row["d_dikte"] * $row["k_soortelijk_gewicht"] / 1000000 * $row["p_aantal"]) + (M_PI_2 * $row["p_schijf"] * 0.5 * $row["p_schijf"] * $row["d_dikte"] * $row["k_soortelijk_gewicht"] / 1000000 * $row["p_aantal"]);	
           $totaal = $totaal+$gewicht;
I hav tried but that didn't work.
Code:
$sql = "SELECT 
    		p.id AS p_id,
    		p.van_id AS p_van_id,
    		p.lengte AS p_lengte,
    		p.breedte AS p_breedte,
    		p.schijf AS p_schijf,
    		p.aantal AS p_aantal,
    		p.charge AS p_charge,
    		p.status AS p_status,
    		p.prijs_gekocht AS p_prijs_gekocht,
    		p.opmerkingen AS p_opmerkingen,
    		p.order AS p_order,
    		k.id AS k_id,
    		k.kwaliteit AS k_kwaliteit,
    		k.soortelijk_gewicht AS k_soortelijk_gewicht,
    		d.dikte AS d_dikte,
    		a.klantnaam AS a_klantnaam,
    		gewicht AS (p_lengte * p_breedte * d_dikte * k_soortelijk_gewicht / 1000000 * p_aantal) + (M_PI_2 * p_schijf * 0.5 * p_schijf * d_dikte * k_soortelijk_gewicht / 1000000 * p_aantal)
    		FROM plaatregistratie AS p
    		LEFT OUTER JOIN kwaliteit AS k 
    		ON k.id = p.kwaliteit_id 
    		LEFT OUTER JOIN dikte AS d
    		ON d.id = p.dikte_id 
    		LEFT OUTER JOIN adressen AS a 
    		ON a.id = p.leverancier_id 
    		ORDER BY p.id DESC
    		LIMIT $currentRecord, $recordsPerPage";
Reply With Quote
  #2 (permalink)  
Old 05-01-09, 01:49
ashish_mat1979 ashish_mat1979 is offline
Registered User
 
Join Date: Aug 2005
Posts: 30
Try this one:

Code:
$sql1 =  SET @total=0;

$sql2 = "SELECT @total,
    		p.id AS p_id,
    		p.van_id AS p_van_id,
    		p.lengte AS p_lengte,
    		p.breedte AS p_breedte,
    		p.schijf AS p_schijf,
    		p.aantal AS p_aantal,
    		p.charge AS p_charge,
    		p.status AS p_status,
    		p.prijs_gekocht AS p_prijs_gekocht,
    		p.opmerkingen AS p_opmerkingen,
    		p.order AS p_order,
    		k.id AS k_id,
    		k.kwaliteit AS k_kwaliteit,
    		k.soortelijk_gewicht AS k_soortelijk_gewicht,
    		d.dikte AS d_dikte,
    		a.klantnaam AS a_klantnaam,
    		(@total:=@total+(p_lengte * p_breedte * d_dikte * k_soortelijk_gewicht / 1000000 * p_aantal) + (M_PI_2 * p_schijf * 0.5 * p_schijf * d_dikte * k_soortelijk_gewicht / 1000000 * p_aantal))
    		FROM plaatregistratie AS p
    		LEFT OUTER JOIN kwaliteit AS k 
    		ON k.id = p.kwaliteit_id 
    		LEFT OUTER JOIN dikte AS d
    		ON d.id = p.dikte_id 
    		LEFT OUTER JOIN adressen AS a 
    		ON a.id = p.leverancier_id 
    		ORDER BY p.id DESC
    		LIMIT $currentRecord, $recordsPerPage";
Execute both queries one after another, you will get total of all records in last row fetched by sql2 in field @total.
__________________
Ashish
Entertainment Overloaded
Reply With Quote
  #3 (permalink)  
Old 05-02-09, 10:38
Muiter Muiter is offline
Registered User
 
Join Date: Dec 2008
Location: Netherlands
Posts: 56
Thank you for your reply, I will give it a try.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On