php - can't find multiple values in SQL -
i have db full of players , trying create page register them specific tournament. tournament director search players username (which "firstname.lastname").
the problem i'm experiencing when run loop echo each $players[$x] gives id first matching db record, , repeats number once each match. rather returning id 7, 11, 26 return 7, 7, 7. please can explain why?
i have written following code in .php file:
session_start(); if (isset($_post['newsearch']) === true && empty($_post['newsearch'] === false)){ require 'dbconnect.php'; $term = $_post['newsearch']; $terms = "%" . $term . "%"; $query = ("select playerid players username '$terms'"); $run_query = mysqli_query($dbcon, $query); $search = mysqli_fetch_assoc($run_query); $players = array (); do{ //get data players table $playerid = $search['playerid']; array_push ($players, $playerid); } while ($dbsearch = mysqli_fetch_assoc($run_query));}
you have more 1 fetch
same query, replace code after $run_query = mysqli_query($dbcon, $query);
code:
$players = array (); while ($dbsearch = mysqli_fetch_assoc($run_query)) { array_push($players, $dbsearch['playerid']);; }
Comments
Post a Comment