php if statment unknown feild value hide

i have a table that i need to show only if contents is in my DB, i can make it work if i know the value of the feild but this field will be peoples names so i just want the table to show if the field is populated

[php]

//variable for showing tenants

$ten_info1 = $row_rsTenant[‘tenTen1FirstN’];

<?php if ($ten_info1 == 'bob'):?> Tenant 1 name <?php echo $row_rsTenant['tenTen1FirstN']; ?> <?php echo $row_rsTenant['tenTen1MiddN']; ?> <?php echo $row_rsTenant['tenTen1SurnN']; ?> Share of rent <?php echo $row_rsTenant['tenTen1Share']; ?> To be paid by <?php echo $row_rsTenant['tenTen1TbePaid']; ?> <? endif; ?>[/php]

so i need to know what to replace bob with so if any name is inserted into the feild the table will show

Try a preg match to look for alpha chars?

[php]
/**

  • Check if there are any matches of alpha chars only ‘+’ denotes more than one.
    **/
    if(preg_match(’/([a-zA-Z]+)/’, $ten_info1) ) { ?>
Tenant 1 name <?php echo $row_rsTenant['tenTen1FirstN']; ?> <?php echo $row_rsTenant['tenTen1MiddN']; ?> <?php echo $row_rsTenant['tenTen1SurnN']; ?> Share of rent <?php echo $row_rsTenant['tenTen1Share']; ?> To be paid by <?php echo $row_rsTenant['tenTen1TbePaid']; ?> <?php } else { // failed :( }[/php]

As a side note, you should really use the full opening tags <?php as opposed to <? to avoid any avoidable issues.

Sponsor our Newsletter | Privacy Policy | Terms of Service