i am working on this search engine. and in the advanced section you can turn on/off some of the options. So it you turn on an option it will search another table and so on.
Instead of building a massive query and left joining lots of stuff. I tried a different approach.
There is always a basic query and it returns the results to an array like this
$sql = mysql_query("SELECT SQL_CACHE id FROM table WHERE field LIKE '$getquery' ORDER BY field");
while ($row = mysql_fetch_array($sql)) {
$idArray[] = $row['id'];
} mysql_free_result($sql);
and if something is turned on then it adds something like this:
if($_POST['value'] == "1") {
$sql = mysql_query("SELECT SQL_CACHE table1_relation_id FROM table2 WHERE field2 LIKE '$getquery' ORDER BY field2");
while ($row = mysql_fetch_array($sql)) {
$idArray[] .= $row['table1_relation_id'];
} mysql_free_result($sql);
} //end if
so basicy i just continue the array and it keeps pumping ids into a big aray. after that i run array_unique and remove all duplicate results and then i foreach and get the whole item info ased on every id. it runs pretty fast.
now i would like to make the second one a function. but when i do that it does not work.
function sample($query, $table, $field) {
$sql = mysql_query("SELECT SQL_CACHE naziv_id FROM ".$table." WHERE ".$field." LIKE '$query'");
while ($row = mysql_fetch_array($sql)) {
$return[] .= $row['naziv_id'];
} mysql_free_result($sql);
return $return;
}
before i put it into a function $idArray vas a single continuous array. And if i try to do it like this:
$arr[] = sample($query, "table1", "filed_id");
$arr[] .= sample($query, "table2", "filed_id");
it returns the result of the first array ok but if there are more then one results in other arrays it returns and arary inside of the array.
like this:
array(4) { [0]=> array(2) { [0]=> string(4) "9057" [1]=> string(5) "14186" } [1]=> string(5) "Array" [2]=> string(5) "Array" [3]=> string(0) "" }
and all i wanna have is a single id variable that has all the id's in it. like $array = 1,2,3,4,5 but from different sources/functions
can you help? thank you so much.