www.webdeveloper.com
Results 1 to 8 of 8

Thread: [RESOLVED] round ()

  1. #1
    Join Date
    Jun 2011
    Location
    California
    Posts
    383

    resolved [RESOLVED] round ()

    if i have a sql statement like so:

    Code:
    SELECT quantity,duration_minutes,
    duration_seconds,
    quantity /
    SUM(duration_minutes + duration_seconds) as total
    From process_data
    GROUP BY quantity,duration_minutes,
    duration_seconds
    The output comes back as 1.6, how do i just round to two using the math round function?

    Thanks in advance.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,537
    PHP Code:
    echo round($value); 
    ...should be sufficient
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jun 2011
    Location
    California
    Posts
    383

    Red face

    Thanks NogDog,

    That worked well, although it's outputting to the nearest decimal but i need it to output to the nearest whole number. I created a new variable $total...

    Here's what i got:

    PHP Code:

    <?php 

    $total 
    sql::query("SELECT 

    quantity,duration_minutes,
    duration_seconds,
    quantity /
    SUM(duration_minutes + duration_seconds) as total
    From process_data
    GROUP BY quantity,duration_minutes,
    duration_seconds"
    )
    ?>


    <?php echo ROUND($total); ?>

    total is 1.688

    I would like the result to be "2"
    but rather it's giving me "17"

    More help would be greatly appreciated.

  4. #4
    Join Date
    Jun 2011
    Location
    California
    Posts
    383
    I thought the syntax was something like:

    ROUND ('$total',00.00) right after the SELECT?

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,537
    Well, $total is probably a resource ID at that point, not the value of that column in the result record. You probably need to use the applicable "fetch" method for whichever database extension you're using. If you want the SQL to round it for you, the specifics may depend on which flavor of DBMS you are using -- with MySQL it should be something like:
    Code:
    ROUND(SUM(duration_minutes + duration_seconds)) as total
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #6
    Join Date
    Jun 2011
    Location
    California
    Posts
    383
    I'm stuck.

  7. #7
    Join Date
    Jun 2011
    Location
    California
    Posts
    383
    you're right.

    when i:

    <?php echo print($total_duration);?>

    it returned Resource id #211

    =/


    <?php

    $total_duration = sql::query("SELECT

    quantity,duration_minutes,
    duration_seconds,
    quantity /
    SUM(duration_minutes + duration_seconds) as total_duration
    From process_data
    GROUP BY quantity,duration_minutes,
    duration_seconds");

    ?>

    <?php echo print($total_duration);?>

  8. #8
    Join Date
    Jun 2011
    Location
    California
    Posts
    383

    Wink

    I figured it out.

    PHP Code:
    <?php 

    $results 
    sql::clean_row("
    SELECT
    quantity,duration_minutes,
    duration_seconds
    From event.dbo.process_data"
    );
    echo 
    $results['duration_minutes'] . " " $results['duration_seconds'] . " " $results['quantity'] . "<br />";
    $total_duration =(($results['duration_minutes'] * 60 $results['duration_seconds'])/60) / $results['quantity'];
    //echo round($total_duration, 1.0) . "<br />";




    echo ROUND($total_duration);
    ?>

    Thanks for the help NogDog.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles