Results 1 to 3 of 3

Thread: Math in query

  1. #1
    Join Date
    Dec 2008
    Location
    Netherlands
    Posts
    58

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

  2. #2
    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.

  3. #3
    Join Date
    Dec 2008
    Location
    Netherlands
    Posts
    58
    Thank you for your reply, I will give it a try.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •