NULL entry

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
nhan
Forum Commoner
Posts: 95
Joined: Sun Feb 27, 2005 8:26 pm
Contact:

NULL entry

Post by nhan »

is there a way i can set the NULL or an empty field in the mysql database to display a text saying "no entries found"?

thanks!

nhan
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

use function is_null()

Code: Select all

if (is_null($yourvar) || empty($yourvar)) {
$yourvar = "no entries found";
}
Last edited by hongco on Thu Apr 21, 2005 3:06 am, edited 2 times in total.
User avatar
nhan
Forum Commoner
Posts: 95
Joined: Sun Feb 27, 2005 8:26 pm
Contact:

Post by nhan »

but how about if the field is really empty, no "NULL" is seen on the database if viewed in mysql?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Code: Select all

SELECT IFNULL(column, 'no entries found') AS column FROM table
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

i fixed the code above
User avatar
nhan
Forum Commoner
Posts: 95
Joined: Sun Feb 27, 2005 8:26 pm
Contact:

Post by nhan »

is this correct??

Code: Select all

Function is_null() 
if (is_null($yourvar) || empty($yourvar)) {$yourvar = &quote;no entries found&quote;;}
User avatar
nhan
Forum Commoner
Posts: 95
Joined: Sun Feb 27, 2005 8:26 pm
Contact:

Post by nhan »

i have already corrected the codes, but still it does not work, the field is empty but it does not display the text "no entries"
:(

thanks so much!
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

comment out the first line Function is_null(); it is not supposed to be there.
if you still have problems, you need to show us your codes
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

re

Post by harrisonad »

NULL is the same as '' and false.

or you can test it's boolean counterpart with:

Code: Select all

if($data['fieldname']){
// do stuff
}else{
echo 'data empty';
}
User avatar
nhan
Forum Commoner
Posts: 95
Joined: Sun Feb 27, 2005 8:26 pm
Contact:

Post by nhan »

Code: Select all

if (is_null($yourvar) || empty($yourvar)) {$yourvar = &quote;no entries found&quote;;}
instead of displaying the result in blank (bec the field is empty)i want it to display a message " no entries"

thanks!
User avatar
nhan
Forum Commoner
Posts: 95
Joined: Sun Feb 27, 2005 8:26 pm
Contact:

Post by nhan »

Code: Select all

<?php
if (is_null($yourvar) || empty($yourvar)) {$yourvar = "no entries found";}

$Today 	= (date ("h:i:s A",time())); 
$day = date( "m-d-y" );
$time = date("h:i:s A");
$db = mysql_connect('localhost', 'user', 'pass') or die("Couldn't connect to the database."); 
mysql_select_db('mydatabase') or die("Couldn't select the database"); 
$query = "SELECT * FROM timein WHERE userName = '$name' ORDER BY timeid DESC LIMIT 1";
$result = mysql_query($query); 
while($nt=mysql_fetch_array($result)){
print "<html><body><span class='style7'>Welcome </span><span class='style9'>$_GET[userName]</span><span class='style7'>, Please submit your time record using the buttons below!</span><br>\n</body></html>";
print "<br>";
print "
<html>
<body>
<br>
<span class='style5'>Your last Time In was on </span>$nt[day] at $nt[timein]<span class='style5'> and your last Time Out was on </span>$nt[timeout]<br>\n</body></html>";

}
?>
Initialy the timein is ok since the user made a timein, my problem is if the user have not yet made a time out, the field is emply so it only display nothing, i just want it to display a message "no entry"

thanks so much!
d11wtq | Please use

Code: Select all

tags instead of code tags to post PHP code   [/size][/color]
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post by duk »

im having a problema about empty entrys in mysql...

i was trying to see if a value X existe in the mysql DB...

if a made

Code: Select all

$sql = "select x from table where y='1'";
$exec = mysql_db_query("DB", $sql);

$result = mysql_fetch_row($exec);
if this give-me 0 rows affected... the code will stop, in that moment and nothing i have after that piece of code... will go on...

i will try, som examples that was gived here... but if anyone have any idea to resolve better this situation tell me pls..

tanks in advance
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

nhan wrote:

Code: Select all

<?php
if (is_null($yourvar) || empty($yourvar)) {$yourvar = "no entries found";}

$Today 	= (date ("h:i:s A",time())); 
$day = date( "m-d-y" );
$time = date("h:i:s A");
$db = mysql_connect('localhost', 'user', 'pass') or die("Couldn't connect to the database."); 
mysql_select_db('mydatabase') or die("Couldn't select the database"); 
$query = "SELECT * FROM timein WHERE userName = '$name' ORDER BY timeid DESC LIMIT 1";
$result = mysql_query($query); 
while($nt=mysql_fetch_array($result)){
print "<html><body><span class='style7'>Welcome </span><span class='style9'>$_GET[userName]</span><span class='style7'>, Please submit your time record using the buttons below!</span><br>\n</body></html>";
print "<br>";
print "
<html>
<body>
<br>
<span class='style5'>Your last Time In was on </span>$nt[day] at $nt[timein]<span class='style5'> and your last Time Out was on </span>$nt[timeout]<br>\n</body></html>";

}
?>
Initialy the timein is ok since the user made a timein, my problem is if the user have not yet made a time out, the field is emply so it only display nothing, i just want it to display a message "no entry"

thanks so much!
d11wtq | Please use

Code: Select all

tags instead of code tags to post PHP code   [/size][/color][/quote]

your script has nothing to do with "yourvar"; therefore, the part:
if (is_null($yourvar) || empty($yourvar)) {$yourvar = "no entries found";}
is useless.

after you fetch the array, that's where you need to check if it is null or empty, to check for timein or day, use the code above and replace $yourvar with timein or day
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

duk wrote:im having a problema about empty entrys in mysql...

i was trying to see if a value X existe in the mysql DB...

if a made

Code: Select all

$sql = "select x from table where y='1'";
$exec = mysql_db_query("DB", $sql);

$result = mysql_fetch_row($exec);
if this give-me 0 rows affected... the code will stop, in that moment and nothing i have after that piece of code... will go on...

i will try, som examples that was gived here... but if anyone have any idea to resolve better this situation tell me <span style='color:blue' title='ignorance is bliss'>please</span>..

tanks in advance
it would've been better if you had started a new thread for your question. Anyway, if the result return 0 rows, then you print some message, if it return some row(s), then do whatever next. Search on how to find number of rows returned for a query.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Complicated is simple. Simple is complicated:
timvw wrote:

Code: Select all

SELECT IFNULL(column, 'no entries found') AS column FROM table
Post Reply