Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Simple PHP code question

    PHP Code:
    <div class="reportBox10">
    <?php $sent1 $db->Execute("select count(*) as count from " TABLE_ORDERS " where orders_status = '6' ");?>
    <?php $sent2 
    $db->Execute("select count(*) as count from " TABLE_ORDERS_2 " where orders_status = '6' ");?>
    <?php $last1 
    $db->Execute("select count(*) as count from " TABLE_ORDERS " where orders_status = '7' ");?>
    <?php $last2 
    $db->Execute("select count(*) as count from " TABLE_ORDERS_2 " where orders_status = '7' ");?>
    <div class="header10">
    <?php 
    if ($sent1->fields['count'] < 1) { 
    echo 
    'It must be Monday, ' $sent1->fields['count'] . ' packages sent so far.'
    } elseif (
    $sent1->fields['count'] <= 500) { 
    echo 
    'Good Job! ' $sent1->fields['count'] . ' packages sent this week!'
    } else { 
    echo 
    'Wow, great work! You have sent ' $sent1->fields['count'] . ' packages this week!'
    }
    ?>
    </div>
    </div>
    What I want to do is have it so it can get the two database fields added together

    $sent1 + $sent2

    and then use them in the if argument together so the totals are used...

  2. #2
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: Simple PHP code question

    Quote Originally Posted by DigitalShadow View Post
    PHP Code:
    <div class="reportBox10">
    <?php $sent1 $db->Execute("select count(*) as count from " TABLE_ORDERS " where orders_status = '6' ");?>
    <?php $sent2 
    $db->Execute("select count(*) as count from " TABLE_ORDERS_2 " where orders_status = '6' ");?>
    <?php $last1 
    $db->Execute("select count(*) as count from " TABLE_ORDERS " where orders_status = '7' ");?>
    <?php $last2 
    $db->Execute("select count(*) as count from " TABLE_ORDERS_2 " where orders_status = '7' ");?>
    <div class="header10">
    <?php 
    if ($sent1->fields['count'] < 1) { 
    echo 
    'It must be Monday, ' $sent1->fields['count'] . ' packages sent so far.'
    } elseif (
    $sent1->fields['count'] <= 500) { 
    echo 
    'Good Job! ' $sent1->fields['count'] . ' packages sent this week!'
    } else { 
    echo 
    'Wow, great work! You have sent ' $sent1->fields['count'] . ' packages this week!'
    }
    ?>
    </div>
    </div>
    What I want to do is have it so it can get the two database fields added together

    $sent1 + $sent2

    and then use them in the if argument together so the totals are used...
    What's wrong with using the 'obvious' method:

    ------------------------------------------------------
    <?php
    $sent = $sent1->fields['count'] + $sent2->fields['count'] ;

    if ($sent < 1) {
    do stuff
    }

    ---------------------------------------------------------

    Cheers
    Rod

  3. #3
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Re: Simple PHP code question

    Quote Originally Posted by RodG View Post
    What's wrong with using the 'obvious' method:
    Nothing, I just suck at code!

  4. #4
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: Simple PHP code question

    Quote Originally Posted by DigitalShadow View Post
    Nothing, I just suck at code!
    LOL. Not exactly the answer I was expecting.

    If my suggestion doesn't work 'as is' - it will be because I didn't account for datatype (It shouldn't be possible to add two strings together to produce a numeric result, even though PHP does generally allow it).

    Better code to use would be:
    $sent = (intval)$sent1->fields['count'] + (intval)$sent2->fields['count'] ;

    This will convert the count values to integers before adding them, thus mitigating datatype mismatch errors before they can occur.

    Cheers
    Rod

  5. #5
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Re: Simple PHP code question

    With a little bit of modification got the code to work just fine, thank you.

 

 

Similar Threads

  1. Simple php question
    By danwebman in forum General Questions
    Replies: 4
    Last Post: 18 Dec 2010, 04:17 PM
  2. A simple question for PHP programmers
    By HTMLGoddess in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 19 Jul 2008, 10:59 AM
  3. A simple .php code question? Please help!
    By triplemoonranch in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 24 Feb 2008, 01:55 AM
  4. Plz answer this simple CODE Question
    By odayict in forum General Questions
    Replies: 3
    Last Post: 10 Jan 2008, 09:26 AM

Posting Permissions

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