Question

I'm trying to make an if statement to enable and disable user account in href link but I want the link display Disable if the Query return active = 1 and enable if the query return 0.

Was it helpful?

Solution

Very unclear what you want exactly. You should rewrite the question more clearly and provide more detail.

At a guess though, is this what you are looking for?

 $queryRes = member_enable(); // assuming this returns 1 or 0
 if($queryRes == 0) {
     echo "<a href='enable_member.php?enab=". urlencode($result['member_id'])."' class=\"button-small blue text_upper round\">Enable</a>";
 } else {
     echo "<a href='disable_member.php?deac=" . urlencode($result['member_id'])."' class=\"button-small blue text_upper round\">Deactivate</a>"; 
 }

UPDATE 1 Edited to include code you posted above. Add a return statement to your member_enable function to return number of rows as mentioned in above answer

UPDATE 2 Sounds like you simply need to retrieve the relevant fields from the DB on page load, loop through them printing out the info and the link, and then, when a disable/enable link is pressed, load a script which enables/disables the account and then returns the admin to the user management page. By reloading the management page, the links will change to the appropriate text as it will be using the updated database values.

OTHER TIPS

Try this:-

$link = '';
if($status == 1)
{
    $link ='<a href="">Profile</a>';
}

echo $link;

Update

function member_enable(){
    $command = mysql_query("SELECT COUNT(member_id) FROM members WHERE active= 1");
    $num_rows = mysql_num_rows($command);

    return $num_rows; 
} 

$status  = member_enable();
if($status >= 1)
{
    echo "<a href='enable_member.php?enab=". urlencode($result['member_id'])."' class=\"button-small blue text_upper round\">Enable</a>";

}else{

    echo "<a href='disable_member.php?deac=" . urlencode($result['member_id'])."' class=\"button-small blue text_upper round\">Deactivate</a>";
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top