Im making a top 10 leaderboard and ive added an option to hide yourself from the table if you dont want to be shown. This option removes you from the table completely. What I want to happen is instead of being removed from the table, have your username be replaced with "[HIDDEN]".

<table class="tborder" border="0" cellspacing="1" width="100%" cellpadding="4">
    <tr class="thead">
        <td>Position</td>
        <td>Username</td>
        <td>Points</td>
        <td>Hide</td>
    </tr>
    <?php

    $i=0;
    if($num>0){
        while ($i < $num) {  
            $username6=mysql_result($result4,$i,"username");
            $points6=mysql_result($result4,$i,"points");
            $hide6=mysql_result($result4,$i,"hide");
            $i++;
            echo "<tr class='trow'><td align='center'>".$i."</td><td align='center'>".$username6."</td><td align='center'>".$points6."</td><td align='center'>".$hide6."</td></tr>"; 
        }
    }

    ?>
</table>

Any help is appreciated. Regards.

Member Avatar for diafol

I'd probabaly do soemthing like this:

<?php

    //...connection details...  

    $table_data = '';
    $i = 1;
    $result = mysql_query("SELECT username, points, hide FROM users ORDER BY points, username LIMIT 10");
    if(mysql_num_rows($result)){
        while($data = mysql_fetch_assoc($result)){
            $u = ($data['hide']) ? '[HIDDEN]' : $data['username'];
            $table_data .= "<tr class='trow'><td>$i</td><td>$u</td><td>{$data['points']}</td></tr>";            
            $i++;   
        }
    }
?>



<!--...top of page...-->

<table class="tborder">
    <thead>
        <tr>
            <td>Position</td>
            <td>Username</td>
            <td>Points</td>
        </tr>
    </thead>
    <tbody>
        <?php echo $table_data;?>
    </tbody>
</table>

This is assuming 'hide' is a tinyint (values = 0 or 1). 1 = hide, 0 = show.

I got this warning: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/bleepye1/public_html/vouchers4.us/leaderboard.php on line 22

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.