Forum Moderators: coopster
<?php
if($hl['type']!= 'N;'){
$myarray = unserialize($hl['type']);
$mylist = implode('<br>',$myarray);
echo $mylist;
} else {
echo 'Information Unavailable';
}
?>
This works well. Since this is posted on a php page that looks like: /page.php?id=9 , if id=9 does not exist in the database, the template page shows "Warning: implode() [function.implode]: Bad arguments. in..." where the information for the field 'type' would be inserted. This is only true if the database entry does not exist.
Though this is a small issue since I am talking about non-existant id numbers, I am still curious how to make the 'type' field also echo 'Information Unavailable' if the id entry does not exist. I tried elseif statements, I tried ¦¦ (or) statements, but I am not able to get this to work.
What is the correct way to do this?
Habtom, I tried your example and it works perfectly but I don't understand why. When I first looked at it, I thought the && would mean that both the 'type' field would have to be 'N;' AND the id number could not exist. I thought this would mess up the pages where the id EXISTED in the database with a type field of 'N;' (that I would no longer get the message 'Information Unavailable' for these pages). However that was not the case, everything works fine. Could you please straighten out my reasoning regarding the && statement? I thought I needed some kind of "or" statement, where type=N; OR id did not exist. I never even considered an && statement.
FiRe, I haven't tried your suggestion yet, but will also try it to see how it works.
Thank you both!
if($hl['type']!= 'N;' && $hl['id']!= ''){
The '&&' in the above line means 'and' and the two conditions should be met for the rest of the code to be executed in the if statement.
This part of the code!= '' ensures that the id is not actually empty, which is not the case you wanted under which the if condition to be executed.
Habtom
Thanks for the explanation. The part I didn't understand is, I thought that if the id # did not exist in the database, the id # was empty. So that pages that didn't exist would have empty "type" fields and empty "id" fields. I thought pages that existed could have a "type" field with a value of "N;" and a value in the "id" field, hense both fields had values. That is why I thought your statement could not work in both of those conditions, but apparently I was wrong.
Thanks again.