-1

Hello All

I have a simple php array, For Example:

$numbers=array("12345","65432","98765");

And SQL Table named: "phones" with the column "TNumbers" and the rows: 654654, 12345, 87878.

Now, What will be the fastest way to return all the values from the array that exist in the SQL server table? (So it should return only this: ("12345"))

Thank you Very Much!!

Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
Eran Levi
  • 877
  • 2
  • 12
  • 31

1 Answers1

0

After some more search i have found the answer, Sorry for that:

$ids = join(',',$numbers);  
$sql = "SELECT * FROM phones WHERE TNumbers IN ($ids)";

Thank you anyway!

Eran Levi
  • 877
  • 2
  • 12
  • 31
  • this is prone to SQL injections, so make sure that your `$numbers` array doesn't contain malicious code! – Misch Feb 20 '13 at 16:33