Jump to content

Recommended Posts

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

Try this.  I haven't executed it, but it should work... I think. :P

 

<?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;

?>

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

Try this.  I haven't executed it, but it should work... I think. :P

 

<?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.

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

)

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 "+" 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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.