Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Hi guys! Need help in PHP plsss? ^_^

    Hi guys! I'm just new to PHP, and I am really having a hard time with it. Could you please help me? ^^ I'm suppose to create a page that will tally all the inputted fields in a table. Each inputted field is equivalent to "1" and each empty field is equivalent to "0". If a field isn't empty then all inputted fields should be sum up. Here's my code...

    $VesselApproached = $row['VesselApproached'];

    if (empty($VesselApproached))
    {
    $VesselApproached = 0;
    }
    else
    {
    $VesselApproached = 1;
    }

    if ($VesselApproached = 1)
    {
    $query_1a = "SELECT SUM(VesselApproached) FROM i_questionnaire_1a";

    $result = mysql_fetch_array($query_1a);
    {
    echo "$VesselApproached";
    }
    }

    I really don't know where to start here. I just searched codes from the internet to help me out.. The problem is... its still not working... Ouch!
    Last edited by SolidScript; 06-22-2012 at 02:11 AM.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    There's a difference between blank (empty) and NULL.
    When a table is created, you may or may not have specified that a column can ever be NULL.
    Or, you may have entered ' ' or '' as a value (space or empty).

    Try both of these queries to see what the result is ...

    PHP Code:

    <?php

    $query_1a 
    "SELECT VesselApproached FROM i_questionnaire_1a WHERE VesselApproached IS NOT NULL";
    $result mysql_fetch_array($query_1a); 
    $num_rows mysql_num_rows($result);
    echo 
    "There are $num_rows that are NOT NULL";

    $query_1a "SELECT VesselApproached FROM i_questionnaire_1a WHERE VesselApproached IS NOT EMPTY";
    $result mysql_fetch_array($query_1a); 
    $num_rows mysql_num_rows($result);
    echo 
    "There are $num_rows that are NOT EMPTY";
    ?>

  • #3
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Both are working, but the $num_rows isn't showing. It only says, "There are "__________" that are NOT EMPTY/NULL"..
    Last edited by SolidScript; 06-22-2012 at 04:07 AM.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Methinks you'll need an mysql_query in there somewhere

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    doh! I didn't even notice that.


    PHP Code:


    <?php 

    $query_1a 
    mysql_query("SELECT VesselApproached FROM i_questionnaire_1a WHERE VesselApproached IS NOT NULL"); 
    $result mysql_fetch_array($query_1a);  
    $num_rows mysql_num_rows($query_1a); 
    echo 
    "There are $num_rows that are NOT NULL"

    $query_2a mysql_query("SELECT VesselApproached FROM i_questionnaire_1a WHERE VesselApproached IS NOT EMPTY"); 
    $result2 mysql_fetch_array($query_2a);  
    $num_rows mysql_num_rows($query_2a); 
    echo 
    "There are $num_rows that are NOT EMPTY"
    ?>

    .
    Last edited by mlseim; 06-22-2012 at 11:30 PM.

  • #6
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question

    The "NOT NULL" query is working. The "NOT EMPTY" isn't..

  • #7
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Wow! That worked! Thanks sooo much! Now I'll be working on the over all percentage of the field. Thanks for helping!


  •  

    Posting Permissions

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