For some reason this always goes to else, there are fields in my database which are empty so im not sure why its not working.
Am i doing it the right way?
if (!isset($row[13]))
echo $row[2]." Worktop";
else
{
echo “<a href='”. $row[13] .“'>”. $row[2]." Worktop</a>";
}
Hi
Here is a good article on Isset and empty.
Thanks guys, will give the above a try when i get home. the field is set a varchar in my db
poops
July 26, 2010, 9:13pm
4
try doing
if (!isset($row[13) || !trim($row[13]))
TriLLi
July 26, 2010, 9:13pm
5
Hi,
if entity from db is empty you get result and $row[13] is set, try to do it this way
var_dump($row) - so you can see value of all elements of an array, and if $row[13] is empty you can then check it this way
if(str_len($row[13])== 0)
{
//code
}
I hope this helps
I am not sure what is the data type of the field/column in the database. Sometimes there might be some spaces or sometimes unknowingly new line characters may exist in the field which means the field is set. So use trim the value and then use empty instead of isset.
I’m guessing $row comes from something such as mysql_fetch_row, or $mysqli->fetch_row().
In that case, you’ll want to use !empty() instead of isset(). It may not hurt to include a call to trim() like poops mentioned.