PHP Mysqli Fetch from table where -
i'm working on user system on website, i've table setup users
users register, want retrieve information table specific users.
users
table 5 columns username, password, email, level, gold
i have $_session['username'] equal logged in username , want level , gold users
, set them $userlevel , $usergold. how can this?
edit
the following code gets users info want specific users info
$sql="select username, level, gold users"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "username: " . $row["username"]. " - level: " . $row["level"]. " - gold: " . $row["gold"]. "<br>"; }
you'll need prevent mysql injection:
$username = mysqli_real_escape_string($conn, $_session['username']);
code select row, username equal user logged in
$sql = "select username, level, gold users `username` = '$username';
to echo, can use existing code
$result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "username: " . $row["username"] . " - level: " . $row["level"] . " - gold: " . $row["gold"]. "<br>"; }
updated reflect mysqli, instead of mysql , mysql code make clearer. @fred-ii- point out.
Comments
Post a Comment