Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-22-2012, 02:09 AM   PM User | #1
SolidScript
New to the CF scene

 
Join Date: Jun 2012
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
SolidScript is an unknown quantity at this point
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..
SolidScript is offline   Reply With Quote
Old 06-22-2012, 02:57 AM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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";
?>
mlseim is offline   Reply With Quote
Old 06-22-2012, 03:28 AM   PM User | #3
SolidScript
New to the CF scene

 
Join Date: Jun 2012
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
SolidScript is an unknown quantity at this point
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..
SolidScript is offline   Reply With Quote
Old 06-22-2012, 05:01 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Methinks you'll need an mysql_query in there somewhere
Fou-Lu is offline   Reply With Quote
Old 06-22-2012, 11:26 PM   PM User | #5
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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..
mlseim is offline   Reply With Quote
Old 06-25-2012, 02:48 AM   PM User | #6
SolidScript
New to the CF scene

 
Join Date: Jun 2012
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
SolidScript is an unknown quantity at this point
Question

The "NOT NULL" query is working. The "NOT EMPTY" isn't..
SolidScript is offline   Reply With Quote
Old 06-25-2012, 06:35 AM   PM User | #7
SolidScript
New to the CF scene

 
Join Date: Jun 2012
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
SolidScript is an unknown quantity at this point
Wow! That worked! Thanks sooo much! Now I'll be working on the over all percentage of the field. Thanks for helping!
SolidScript is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:19 PM.


Advertisement
Log in to turn off these ads.