NULL entry
Moderator: General Moderators
NULL entry
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
thanks!
nhan
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.
Code: Select all
SELECT IFNULL(column, 'no entries found') AS column FROM tableis this correct??
Code: Select all
Function is_null()
if (is_null($yourvar) || empty($yourvar)) {$yourvar = "e;no entries found"e;;}- harrisonad
- Forum Contributor
- Posts: 288
- Joined: Fri Oct 15, 2004 4:58 am
- Location: Philippines
- Contact:
re
NULL is the same as '' and false.
or you can test it's boolean counterpart with:
or you can test it's boolean counterpart with:
Code: Select all
if($data['fieldname']){
// do stuff
}else{
echo 'data empty';
}Code: Select all
if (is_null($yourvar) || empty($yourvar)) {$yourvar = "e;no entries found"e;;}thanks!
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>";
}
?>thanks so much!
d11wtq | Please use
Code: Select all
tags instead of code tags to post PHP code [/size][/color]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
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
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);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
nhan wrote: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"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>"; } ?>
thanks so much!
d11wtq | Please useCode: 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
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.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
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...Code: Select all
$sql = "select x from table where y='1'"; $exec = mysql_db_query("DB", $sql); $result = mysql_fetch_row($exec);
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
Complicated is simple. Simple is complicated:
timvw wrote:Code: Select all
SELECT IFNULL(column, 'no entries found') AS column FROM table