-4

I have absolutely no idea where to start.

I have a table called "users" in my database called "database":

NAME | POINTS
John 24
Marrie 32
Moritz 11
Adam 99
Hans 34
Monica 58

I also have this

    <?php
    $users = array("Adam", "Hans", "Monica");
    ?> 

What I would like to do is: Connect to mysql table "users" then database called "database", search for the names mentioned in the array $users and give me the list of their points (without names).

SO it should echo

99
34
58
Nate
  • 1
  • 2
  • 3
    this is both unclear and too broad. Read up on the many tutorials and manuals then edit your post to contain what you had problems with. – Funk Forty Niner Feb 15 '18 at 13:31
  • i don't know how to use php arrays with mysql commands – Nate Feb 15 '18 at 13:33
  • A good tutorial is e.g. on [w3schools](https://www.w3schools.com/php/php_mysql_intro.asp) – Julien Ambos Feb 15 '18 at 13:35
  • Also, although it's a bit high-brow, see about using IN() in conjunction with prepared statements. – Strawberry Feb 15 '18 at 13:41
  • Possible duplicate of [Passing an array to a query using a WHERE clause](https://stackoverflow.com/questions/907806/passing-an-array-to-a-query-using-a-where-clause) – Nigel Ren Feb 15 '18 at 13:49

1 Answers1

1

You can do this using IN with MySQL:

$users = array('Adam', 'Hans', 'Monica');
$users_joined = join("','",$users);   
$sql = "SELECT POINTS FROM users WHERE NAME IN ('$users_joined')";

More information: Stackoverflow - passing an array in where clause