Solved

PHP/MySql search engine special characters paging problem

Posted on 2010-08-14
14
413 Views
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?
0
Comment
Question by:mankis
  • 8
  • 4
  • 2
14 Comments
 
LVL 6

Expert Comment

by:nitinsawhney
Comment Utility
Hope you are using urldecode before using the value for query?
0
 

Author Comment

by:mankis
Comment Utility
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
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
Comment Utility
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
 

Author Comment

by:mankis
Comment Utility
Google has the same problem. In Mozilla it displays special characters correctly but in IE it dsplays % and numbers instead of special character
0
 

Author Comment

by:mankis
Comment Utility
What is wrong with solution with database and session? Will I have problems?
0
 
LVL 6

Accepted Solution

by:
nitinsawhney earned 250 total points
Comment Utility
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
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:mankis
Comment Utility
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
 

Author Comment

by:mankis
Comment Utility
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
 

Author Comment

by:mankis
Comment Utility
And table in database
tbl-search.gif
0
 

Author Comment

by:mankis
Comment Utility
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
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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
 

Author Closing Comment

by:mankis
Comment Utility
Thank you for your help. I will stick to this solution with database and session id.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now