Page 1 of 2

NULL entry

Posted: Thu Apr 21, 2005 2:32 am
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

Posted: Thu Apr 21, 2005 2:46 am
by hongco
use function is_null()

Code: Select all

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

Posted: Thu Apr 21, 2005 2:59 am
by nhan
but how about if the field is really empty, no "NULL" is seen on the database if viewed in mysql?

Posted: Thu Apr 21, 2005 3:05 am
by timvw

Code: Select all

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

Posted: Thu Apr 21, 2005 3:06 am
by hongco
i fixed the code above

Posted: Thu Apr 21, 2005 3:15 am
by nhan
is this correct??

Code: Select all

Function is_null() 
if (is_null($yourvar) || empty($yourvar)) {$yourvar = &quote;no entries found&quote;;}

Posted: Thu Apr 21, 2005 3:19 am
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!

Posted: Thu Apr 21, 2005 3:22 am
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

re

Posted: Thu Apr 21, 2005 5:17 am
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';
}

Posted: Thu Apr 21, 2005 5:47 am
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!

Posted: Thu Apr 21, 2005 6:35 am
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]

Posted: Thu Apr 21, 2005 10:30 am
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

Posted: Thu Apr 21, 2005 12:52 pm
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

Posted: Thu Apr 21, 2005 12:55 pm
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.

Posted: Thu Apr 21, 2005 1:02 pm
by patrikG
Complicated is simple. Simple is complicated:
timvw wrote:

Code: Select all

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