Hi, I have an ajax script with currently uses an array to search through, however i want to change this so instead of looping through an array it searched through a table in a database. How would i do this to the below: <?php $q = ''; if (isset($_GET['q'])) { $q = strtolower($_GET['q']); } if (!$q) { return; } $items = array( "Science Grade 2 with Henry Lecture" => "", "Maths Grade 6 with Henry Lecture" => "", "Social Studies Grade 2 with Henry Lecture" => "", "World War 2 Battle" => "" ); foreach ($items as $key => $value) { if (strpos(strtolower($key), $q) !== false) { echo "$key|$value\n"; } } ?> PHP:
Change these values with your own : table_name,column_to_check,column_to_echo $items = array( "Science Grade 2 with Henry Lecture" => "", "Maths Grade 6 with Henry Lecture" => "", "Social Studies Grade 2 with Henry Lecture" => "", "World War 2 Battle" => "" ); $result = mysql_query("SELECT * FROM table_name WHERE column_to_check IN (".implode(",",$items).")"); if(mysql_num_rows($result) > 0) { while($row = mysql_fetch_array($result)) { echo $row['column_to_echo'].'<br />'; } } else { echo 'No results found !'; } PHP:
Oh... miss-read your post... change this : "SELECT * FROM table_name WHERE column_to_check IN (".implode(",",$items).")" to "SELECT * FROM table_name WHERE column_to_check = '".$_GET['q']."'"