Joins

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

This is a challenge when using for loops and foreach loops. Normally, when I code loops like this, just before the loop, I will run an if to check for the count of the array. If there are results in the array, loop them, if not handle the exception with something else. What you end up with is code like:

Code: Select all

<?php
if (count($looparray1) > 0)
{
    // There are records in the result array, loop 'em
    foreach ($looparray1 as $arrayval1)
    {
        // ... Do something here
    }
}
else
{
    // ... Perform exception handling here
}
?>
Post Reply