Jump to content

Pass an array to a quyery string


mjahkoh

Recommended Posts

You nearly said it in your question.

 

<?php

  $arr = array(1,2,3);
  $sql = "SELECT * FROM tbl WHERE hd IN('" . implode(",",$arr) . "')";

?>

 

Keep in mind, this isn't a secure way of doing it.

 

If the values in the array come from user entered input (in this example, hard to tell), you need to sanitize each value.  That means looping through the array, and applying mysql_escape_string (or applicable db version) to each entry.  I would create a function for doing this.  Read up on SQL injection attacks.

 

Regards,

Mark

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.