how to run foreach loop with ternary condition

Posted by I Like PHP on Stack Overflow See other posts from Stack Overflow or by I Like PHP
Published on 2010-03-26T12:49:00Z Indexed on 2010/03/26 12:53 UTC
Read the original article Hit count: 286

Filed under:
|

i have two foreach loop to display some data, but i want to use a single foreach on basis of database result.

means if there is any row returns from database then forach($first as $fk=>$fv) should execute otherwise foreach($other as $ok) should execute. i m unsing below ternary operator which gives parse error

$n=$db->numRows($taskData); // databsse results

<?php ($n) ? foreach ($first as $fk=>$fv) : foreach ($other as $ok) 
{ ?>
<table><tr><td>......some data...</td></tr></table>
<?php } ?>

please suggest me how to handle such condition via ternary operator or any other idea.

Thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about foreach-value