0

hi, all i am new in php developing

i need to know how i could make a user data hidden or inactive to the viewer of my website

without deleting this user data from my database


can i do that using php code?

if yes what is this coding criteria

thanks in advance

6
Contributors
8
Replies
27
Views
7 Years
Discussion Span
Last Post by Er Richa
0

You can add another field on your users table named 'activity' where you can flag a user as 'active' or 'inactive.' That way whenever you query the database you just have to "SELECT * FROM users WHERE activity = 'active'" so that it won't show your inactive users.

0

More info please. As mentioned by Shinehah, a flag field like "activity" set to 0 or 1 (default) would work for most cases, but not knowing the actual use case, it's difficult to say.

0

here is my code

mysql_connect("localhost","root","");
         mysql_select_db("dbname");
       if($_REQUEST['select'] == "Activate")

      {
      mysql_query("update table1 set status=1 where P_id in $Patient_id");

}
if($_REQUEST['select'] == "Deactivate")

      {
      mysql_query("update table1 set status=0 where P_id in $Patient_id");

}

      $query = "SELECT * FROM `table1`";

      $dd=mysql_query($query);
 ?>

is this true?

Edited by mike_2000_17: Fixed formatting

0

Assuming the status column is the active flag you need, just change the last query to be:

SELECT * FROM TABLE1 WHERE status = 1
0

Urghh. $_REQUEST!

mysql_connect("localhost","root","");
mysql_select_db("dbname");

if($_POST['select'] == "Activate"){
  mysql_query("UPDATE table1 SET status=1 WHERE P_id = $Patient_id");
}
if($_POST['select'] == "Deactivate"){
  mysql_query("UPDATE table1 SET status=0 WHERE P_id = $Patient_id");
}

$query = "SELECT * FROM table1";
$dd=mysql_query($query);

Can't see anything wrong with the above now. As long as $Patient_id is an integer. Also ensure that when you set the variable, it had the same case, i.e. $Patient_id and not $patient_id - they are treated as 2 different variables in php.

You can test to see if an update query has been completed successfully:

if($_POST['select'] == "Activate"){
  mysql_query("UPDATE table1 SET status=1 WHERE P_id = $Patient_id");
  echo "UPDATE table1 SET status=1 WHERE P_id = $Patient_id"; //check query
}
if($_POST['select'] == "Deactivate"){
  mysql_query("UPDATE table1 SET status=0 WHERE P_id = $Patient_id");
  echo "UPDATE table1 SET status=0 WHERE P_id = $Patient_id"; //check query
}

if(mysql_affected_rows()>0){
  echo "table updated";
}else{
  echo "table not updated";
}

Purely for testing.

0

i am unable to understand that how we will store the status (1 or 0) in our database?what should be the type of the status in the database?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.