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!
Hi there,
I have a critical condition. I want to check a mysql field value whether it is empty or not. If empty then to show 'No Value' else show the value. So I want to execute following query:
<?php
function checkv($field){
global $row;
if ($row[$field]=""){
echo 'No value;
}else{
echo $row[$field];
}
}
$result = mysql_query("SELECT * FROM $table WHERE some_column=some_condition");
while($row=mysql_fetch_assoc($result){
?>
Fullname: <?php checkv(fullname); ?>
Lastname: <?php checkv(lastname); ?>
<?php
}
?>
But nothing is outputting except html part Fullname: and Lastname. No mysql error is coming if I add 'or die(mysql_error())' at the end of mysql_query.
How I can accomplish the above condition and display mysql field value?
Hi Celauran,
Thanks for your reply and sorry for my silly mistake I made. Now problem is solved. It is showing what I want but with using global.
How can I bring expected result (if mysql field value is empty then show 'No Value') without using global in this case?
Expecting your help.
Best Regards
There is an OO design for this type of error checking that is usually called a Validator or Validation Rule. If you are interested I can show you that code.