Page 1 of 1

If highest number show, else?!?

Posted: Sat Jan 31, 2009 8:24 am
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...

Re: If highest number show, else?!?

Posted: Sat Jan 31, 2009 2:12 pm
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
 
}