andybeak icon

Find users with a status

andybeak | PRO | 02/26/25 03:42:26 PM UTC (Edited) | 0 ⭐ | 10307 👁️ | Never ⏰ | []
PHP |

600 B

|

None

|

0 👍

/

0 👎

function getUsersByStatus($desiredStatus) {
    $matchingUsers = [];
    
    $conn = new mysqli("localhost", "db_user", "db_password", "users_database");
    
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    
    $result = $conn->query("SELECT * FROM users");
    
    while ($row = $result->fetch_assoc()) {
        if ($row['status'] == $desiredStatus) {
            $matchingUsers[] = $row;
        }
    }
    
    $conn->close();
    
    return $matchingUsers;
}
 
// example of using it
$registeredUsers = getUsersByStatus("registered");

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎