mySQL check for match in database (array) |
mySQL check for match in database (array) |
sanoj96 |
Jul 27 2020, 12:56 PM
Post
#1
|
Advanced Member Group: Members Posts: 118 Joined: 18-September 12 Member No.: 17,803 |
Hello,
So i have had this script going for a while, not noticing anything since it have given me an output. But yesterday i noticed that some useres had was missing on the list. So i am trying to get all useres that has u_role 498147873003798539. The problem is that useres that has the role in the second place in the array like this : 123451232132131, 498147873003798539, 123154512555433 is getting displayed, but when it is in the 3rd or more position it wont display. This is my code: CODE $array = array('498147873003798539'); //u_role to find in the array ('12345678910, 10987654321') $sql = "SELECT * FROM userlist WHERE u_roles IN (".implode(',', $array).")"; //sql $result = mysqli_query($db_conn, $sql); //sql $array = mysqli_fetch_assoc($result); //sql $exploded = explode(",", $array['u_roles']); $gamers = []; foreach ($exploded as $row){ $query = "SELECT * FROM userlist WHERE u_roles = $row"; $res = mysqli_query($db_conn, $query); $arr = mysqli_fetch_assoc($res); $gamers[] = $arr["u_roles"]; while($test = mysqli_fetch_assoc($res)){ if($test["u_nickname"] == "undefined"){ echo "<p>Username: " .$test["u_name"]. "</p>"; }else{ //echo "id: " .$test["u_userid"]. "<br>"; //echo "Name: " .$test["u_name"]. "<br>"; echo "<p>Nickname: " .$test["u_nickname"]. "</p>"; //echo "Role: " . $test["u_roles"]; } } } it is proberly a easy fix, but for some reason i cant find the problem, any help will be appriciated. |
sanoj96 |
Jul 31 2020, 04:12 PM
Post
#2
|
Advanced Member Group: Members Posts: 118 Joined: 18-September 12 Member No.: 17,803 |
Yea that is true, this is just a quick script, that i have to make a few tasks i have automatic. There is no login or anything in this database, and all it is going to do is to display the users with different roles in the correct area But yes, it would be best practic to create a good database design!
|
Lo-Fi Version | Time is now: 19th April 2024 - 06:34 PM |