Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


PHP/MySql search engine special characters paging problem

Posted on 2010-08-14
Medium Priority
Last Modified: 2012-08-14
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?
Question by:mankis
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
  • 2

Expert Comment

ID: 33436297
Hope you are using urldecode before using the value for query?

Author Comment

ID: 33436514
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?
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 total points
ID: 33436955
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.

Here is the URL for page 2 of that same search:

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
Technology Partners: 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!


Author Comment

ID: 33437247
Google has the same problem. In Mozilla it displays special characters correctly but in IE it dsplays % and numbers instead of special character

Author Comment

ID: 33437252
What is wrong with solution with database and session? Will I have problems?

Accepted Solution

nitinsawhney earned 1000 total points
ID: 33437432
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.
LVL 111

Expert Comment

by:Ray Paseur
ID: 33437851
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!

Author Comment

ID: 33439795
Sorry for delayed response. Here is the image of google addressbar and here is my code:
function searchTerm(){
			$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;


$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


Author Comment

ID: 33439796
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">
      <input type="hidden" name="action" id="action" value="add" />
        <input type="text" name="s" id="s" class="input" />
      <td><input type="image" src="<?=DOMAIN?>img/searchbtn.jpg"  name="Submit" value="submit" class="submit" /></td>

Open in new window


Author Comment

ID: 33439804
And table in database

Author Comment

ID: 33439820
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).
LVL 111

Expert Comment

by:Ray Paseur
ID: 33440434
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.

The second URL ends in percent-C4-percent-8C
LVL 111

Expert Comment

by:Ray Paseur
ID: 33440457
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:
<?php // RAY_temp_mankis.php

$x = '&#269;';

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

$x = $_GET['q'];

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

Open in new window


Author Closing Comment

ID: 33446271
Thank you for your help. I will stick to this solution with database and session id.

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question