Solved

PHP/MySql search engine special characters paging problem

Posted on 2010-08-14
14
414 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
ID: 33436297
Hope you are using urldecode before using the value for query?
0
 

Author Comment

by:mankis
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?
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 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.
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
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
0
 

Author Comment

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

Accepted Solution

by:
nitinsawhney earned 250 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.
0
 
LVL 108

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!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:mankis
ID: 33439795
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
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">
    <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
ID: 33439804
And table in database
tbl-search.gif
0
 

Author Comment

by:mankis
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).
IE-address-bar.gif
0
 
LVL 108

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.
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
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:
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
ID: 33446271
Thank you for your help. I will stick to this solution with database and session id.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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 count occurrences of each item in an array.

911 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

16 Experts available now in Live!

Get 1:1 Help Now