• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 427
  • Last Modified:

PHP/MySql search engine special characters paging problem

When I submit search form (method GET) I got results from search query (although special characters display like % and numbers in address bar of the browser). I also have paging but links for page numbers are not like submit form and when I click on page number query won't work no more for words with special caracters. It's beacuse I GET $search term for page numbers from url and not from submit form. I have tried urlencode and rawurlencode and results change depending on the browser (somewhere query works somwhere don't). Is there some easy solution for search engine with paging for words with special characters?
If not what do you think of making a new temp table in MySql database that will hold session and search term?
0
mankis
Asked:
mankis
  • 8
  • 4
  • 2
2 Solutions
 
nitinsawhneyCommented:
Hope you are using urldecode before using the value for query?
0
 
mankisAuthor Commented:
I have tried everything and some things work for some browsers some don't (I don't like checking all browsers every time). Do you know for some tutorial with complete solution? I need to display this word with special character in address bar, title of the page and paging urls and use it as a value for query. It's pretty hard to find on internet example of search engine with paging for special characters.

While I was waiting answer I have started to build a table in MySql to use it for temporary storage of search terms and session id of the user. Now I have form with POST method, and I compare value in that temp table with values in product table. Since now it works fine and i don't have any problem of displaying special character in page title, address bar and paging url. I have never run into this solution on internet so I'm not shore is that ok? Wha do you think? Can I stick on this solution?
0
 
Ray PaseurCommented:
For search strings, you should use GET method.  It is good enough for Google - they seem to have mastered searching.

Here is a search URL.
http://www.google.com/#hl=en&q=goose

Here is the URL for page 2 of that same search:
http://www.google.com/#q=goose&hl=en&start=10

I am fairly sure Google (and Wikipedia) can deal with special characters in the search string, so you might try testing Google's search with your special characters.  See how they handle the issue.  And then post a link to the Google search that illustrates your search string, containing your special characters, so we can test it.  Thanks, ~Ray
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mankisAuthor Commented:
Google has the same problem. In Mozilla it displays special characters correctly but in IE it dsplays % and numbers instead of special character
0
 
mankisAuthor Commented:
What is wrong with solution with database and session? Will I have problems?
0
 
nitinsawhneyCommented:
No I don't foresee any issues with a session based solution. Except there will be little overhead of pulling the information from the session.

I think at this point session based solution is best.
0
 
Ray PaseurCommented:
Can you show us a code sample that would use a session-and-data base solution?  Or better yet, please show us the example that demonstrates the problem that you say Google has - I would like to see that in action.   I expect the problem may not be Google, so I would like to see it.  Thanks!
0
 
mankisAuthor Commented:
Sorry for delayed response. Here is the image of google addressbar and here is my code:
function searchTerm(){
		$sid=session_id();
		
			$q = "SELECT sr_term AS search FROM tpl_search WHERE sr_session_id='$sid'";
			$result = dbQuery($q);
			$row  = mysql_fetch_assoc($result);
			$srtan = $row['search'];
		
		 return $srtan;
}

$searchTerm=searchTerm();

$productsPerRow = 2;
$productsPerPage = 20;



$searchTerm= mysql_real_escape_string($searchTerm);


$sql = "SELECT pd_id, pd_name, pd_price, pd_thumbnail, pd_description, pd_qty
		FROM tbl_product pd
		WHERE pd.pd_name LIKE  '%$searchTerm%' OR pd.pd_sifra LIKE '$searchTerm'   
		GROUP BY pd_id ORDER BY pd_name ";


$result     = dbQuery(getPagingQuery($sql, $productsPerPage));


$pagingLink = getPagingLink($sql, $productsPerPage, "page=6&s=".$searchTerm);

Open in new window

google-addressbar-specialcharact.gif
search-functions.php
0
 
mankisAuthor Commented:
Here is form
<form id="form1" name="form1" method="POST" action="<?=DOMAIN?>library/search-functions.php">
  <table width="242" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>
      <input type="hidden" name="action" id="action" value="add" />
        <label>
        <input type="text" name="s" id="s" class="input" />
         
        </label>
            </td>
      <td><input type="image" src="<?=DOMAIN?>img/searchbtn.jpg"  name="Submit" value="submit" class="submit" /></td>
    </tr>
  </table> 
  </form>

Open in new window

0
 
mankisAuthor Commented:
And table in database
tbl-search.gif
0
 
mankisAuthor Commented:
I just found out that it doesn't work perfectly. Paging is good. I have special characters in most browsers but when the form is submited I get htmlentities for example &#269;
How can i resolve this? If I can resolve this than everything would work perfect (from my point of view).
IE-address-bar.gif
0
 
Ray PaseurCommented:
Interesting... The hacek c character resolves to the same address as this URL in Wikipedia.  Not sure what EE will do with these characters, so I will describe what I posted here.

The first URL ends in the hacek c.
http://en.wikipedia.org/wiki/c

The second URL ends in percent-C4-percent-8C
http://en.wikipedia.org/wiki/%C4%8C
0
 
Ray PaseurCommented:
And EE "translated" the hacek c into the lower-case english language letter "c" -- however the second link worked correctly.

I had less luck with the URL string shown here:
http://www.laprbass.com/RAY_temp_mankis.php?q=%C4%8C
<?php // RAY_temp_mankis.php
error_reporting(E_ALL);

// AN ENTITY
$x = '&#269;';

// SHOW IT
$y = '<br/>HERE IS X:' . $x;
echo $y;

// FROM THE URL STRING
$x = $_GET['q'];

// SHOW IT
$y = '<br/>HERE IS X:' . $x;
echo $y;

Open in new window

0
 
mankisAuthor Commented:
Thank you for your help. I will stick to this solution with database and session id.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 8
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now