If highest number show, else?!?

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!

Moderator: General Moderators

Post Reply
jmansa
Forum Commoner
Posts: 81
Joined: Wed Aug 23, 2006 4:00 am

If highest number show, else?!?

Post by jmansa »

This is also for my re-ordering script. I want the highest record to show an arrow down and the lowest record to show an arrow up, and all the records in between to show both a record up and down... I have managed to get the highest to only show a record down, but can't get the lowest to show only a record up... This is what I have done:

Code: Select all

$i = 0;
        $sql2 = $db->sql_query("SELECT *, (SELECT COUNT(uid) AS count FROM ".$prefix."_links WHERE uid=$userid AND catid='$catid' ORDER BY order_no ASC) AS items " 
        ." FROM ".$prefix."_links WHERE uid=$userid AND catid='$catid' ORDER BY order_no ASC");
        while ($row2 = $db->sql_fetchrow($sql2)) {
 
echo '<div class="links"><a href="'.(strstr($row2['url'], 'http') == false ? 'http://' : '').$row2['url'].'">'.$row2['name'].'</a><div id="link-edit">';
        
        if ( $i > 0 ) {
            echo '<a href="users.php?ies=LinkReOrder&uid='.$row2['uid'].'&linkid='.$row2['linkid'].'&move=up">';
            echo '<img src="images/Aesthetica2-icons/up-10X10.png" alt="'._UP.'" border="0"></a>';
        }
        echo '&nbsp;';
        
        if ( $i < $row2['items']) {
        echo '<a href="users.php?ies=LinkReOrder&uid='.$row2['uid'].'&linkid='.$row2['linkid'].'&move=down">';
        echo '<img src="images/Aesthetica2-icons/down-10x10.png" alt="'._DOWN.'" border="0"></a>';
        }
        echo '</div><br></div>';
        
        $i++;
    
        }
Hope somebody can help...
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: If highest number show, else?!?

Post by jaoudestudios »

Use mysql_num_rows to count the results or if $row2['items'] is the size of your results then use another conditional statement against $i

Code: Select all

if ($i == 0) {
// first result returned
 
}
if ($i == $row2['items']) {
// last result returned
 
}
Post Reply