HDFilmMaker2112 Posted May 16, 2011 Share Posted May 16, 2011 elseif(isset($_GET['search'])){ $search=$_POST['search']; $search=str_replace(" ", "+", $search); header("Location: ./index.php?q=".$search); } elseif(isset($_GET['q'])){ $search=$_GET['q']; $keywords=explode("+",$search); $sql10000="SELECT product_id FROM $tbl_name2 WHERE "; while($query10000=each($keywords)){ $sql10000.="keyword LIKE '%".$query10000."%' OR"; } $sql10000=substr($sql10000,0,(strLen($sql10000)-3)); $content=$sql10000; That is returning this: SELECT product_id FROM keywords WHERE keyword LIKE %Array% For some reason it's showing "Array", it should be looping through the keywords array. Link to comment https://forums.phpfreaks.com/topic/236575-not-showing-array-just-array/ Share on other sites More sharing options...
zer0day Posted May 16, 2011 Share Posted May 16, 2011 Try this. I haven't executed it, but it should work... I think. <?php elseif(isset($_GET['search'])) { $search = $_POST['search']; $search = str_replace(" ", "+", $search); header("Location: ./index.php?q=".$search); } elseif(isset($_GET['q'])) { $search = $_GET['q']; $keywords = explode("+", $search); $sql10000 = "SELECT product_id FROM $tbl_name2 WHERE "; } foreach($keywords as $query10000) { $sql10000 .= "keyword LIKE '%".$query10000."%' OR "; } $sql10000 = substr($sql10000,0,(strLen($sql10000)-3)); $content = $sql10000; ?> Link to comment https://forums.phpfreaks.com/topic/236575-not-showing-array-just-array/#findComment-1216182 Share on other sites More sharing options...
kenrbnsn Posted May 16, 2011 Share Posted May 16, 2011 What is the value of the variable $keywords? Post the result of <?php echo '<pre>' . print_r($keywords,true) . '</pre>'; ?> If $keywords is an array, you can create the query like this: <?php $q = "SELECT product_id FROM $tbl_name2 WHERE keyword like '%" . implode("%' or keyword like '%",$keywords) . "%'"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/236575-not-showing-array-just-array/#findComment-1216183 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 16, 2011 Author Share Posted May 16, 2011 Try this. I haven't executed it, but it should work... I think. <?php elseif(isset($_GET['search'])) { $search = $_POST['search']; $search = str_replace(" ", "+", $search); header("Location: ./index.php?q=".$search); } elseif(isset($_GET['q'])) { $search = $_GET['q']; $keywords = explode("+", $search); $sql10000 = "SELECT product_id FROM $tbl_name2 WHERE "; } foreach($keywords as $query10000) { $sql10000 .= "keyword LIKE '%".$query10000."%' OR "; } $sql10000 = substr($sql10000,0,(strLen($sql10000)-3)); $content = $sql10000; ?> Alright, that got rid of the "Array" and placed it with the data, but it's now come up as '%test test2%'... Don't get why, I've had this problem all day with it not add the closing % after test with the closing single quote and then opening % and single quote for test2. Link to comment https://forums.phpfreaks.com/topic/236575-not-showing-array-just-array/#findComment-1216184 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 16, 2011 Author Share Posted May 16, 2011 What is the value of the variable $keywords? Post the result of <?php echo '<pre>' . print_r($keywords,true) . '</pre>'; ?> If $keywords is an array, you can create the query like this: <?php $q = "SELECT product_id FROM $tbl_name2 WHERE keyword like '%" . implode("%' or keyword like '%",$keywords) . "%'"; ?> Ken tried this and get the '%test test2 %' problem as well. The URL of the page has q=test+test2. Meaning it should be pulled into the explode and be placed into an array of $keywords("test","test2")... if I'm not mistaken. echo '<pre>' . print_r($keywords,true) . '</pre>'; That returns: Array ( [0] => test test2 ) On my computer running Windows XP with FireFox on my windows 7 comp with FireFox it returns something different (weird since the computer shouldn't be doing any processing): Array ( [0] => test ) Link to comment https://forums.phpfreaks.com/topic/236575-not-showing-array-just-array/#findComment-1216185 Share on other sites More sharing options...
kenrbnsn Posted May 16, 2011 Share Posted May 16, 2011 The "+" character has special meaning when used in a URL. It will replaced by a space. Pick another character for your deliminator, such as a "~" or "`" or "|" or any character that you're not expecting to be in a keyword. Ken Link to comment https://forums.phpfreaks.com/topic/236575-not-showing-array-just-array/#findComment-1216190 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 16, 2011 Author Share Posted May 16, 2011 The "+" character has special meaning when used in a URL. It will replaced by a space. Pick another character for your deliminator, such as a "~" or "`" or "|" or any character that you're not expecting to be in a keyword. Ken The reason I was trying to use "+" is because I see it all the time in search engine URLs, and a lot of other stores. Link to comment https://forums.phpfreaks.com/topic/236575-not-showing-array-just-array/#findComment-1216193 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 16, 2011 Author Share Posted May 16, 2011 Well, anyway I changed it to "." Working now. Thanks for the help. Curious to know how Google, Bing, and a lot of other major retailers manage to use "+" in their search queries to hold together the string. Link to comment https://forums.phpfreaks.com/topic/236575-not-showing-array-just-array/#findComment-1216203 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.