1

I have an array which looks like this
"76561198086947554", "76561198133402236"

I need to query each value individually and display the queried data on a page
$pid would be a single value of the array above which I am wanting to query indiviually

$sqlget = "SELECT * FROM players WHERE pid='$pid'";
$result = $conn->query($sqlget);

if ($result->num_rows > 0) {
  while ($row = $result->fetch_assoc()) {
    $name = $row["name"];

    echo "<div>
      Members: ".$name."
    <div>";
  }
}

I am happy to try explain it a bit more if you would like me to.

  • Your query is open to [SQL Injection](https://stackoverflow.com/q/332365/2469308) related issues. Please use [Prepared Statements](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Madhur Bhaiya Sep 30 '18 at 12:46

1 Answers1

0

First you use mysql query that have issues with sql injection and is outdated. Second, if i have understand you need in your WHERE clause the pid value to be in the array you have so your query should be like this:

$your_array = "76561198086947554, 76561198133402236";
$sqlget = " SELECT * FROM players WHERE pid IN ('".$your_array."') "; 
// here you check if pid is in array values
... // the other code

Hope it helps and try to convert your code using PDO statements or mysqli.

Sigma
  • 387
  • 3
  • 17
  • Will that query each value in the array? – Josh Lisher Sep 30 '18 at 13:25
  • Yes, for example if in your array you have 100 values, the query will check each value to see if is equal to pid value. The in is a build in function of SQL. – Sigma Sep 30 '18 at 13:29
  • How do I then put the queried value into a new array which contains all the queried values of the other pids from the original array? – Josh Lisher Sep 30 '18 at 13:34
  • Is not so clear to me... please make an example of what you are trying to do and the expected result. Thanks – Sigma Sep 30 '18 at 13:40
  • Does this make sense? http://joshlisher.phy.sx/ss/images/wordpad_2018-09-30_14-46-19.png – Josh Lisher Sep 30 '18 at 13:46