Link to home
Start Free TrialLog in
Avatar of mankis
mankisFlag for Croatia

asked on

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?
Avatar of nitinsawhney
nitinsawhney
Flag of India image

Hope you are using urldecode before using the value for query?
Avatar of mankis

ASKER

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?
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mankis

ASKER

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

ASKER

What is wrong with solution with database and session? Will I have problems?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!
Avatar of mankis

ASKER

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
Avatar of mankis

ASKER

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

Avatar of mankis

ASKER

And table in database
tbl-search.gif
Avatar of mankis

ASKER

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

Avatar of mankis

ASKER

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