Skip to content

Search with query sent via GET parameters like wordpress

World Wide Web Server edited this page Jul 4, 2012 · 14 revisions

Category:Approaches

Advantages: you can bookmark your searches, and they show up in your history, etc. (I guess this is why wordpress uses it, or maybe its just convenient, whatever).

[code] function search() {

$this->load->helper('url');   //required for base_url()

$arr = explode('?s=',  $_SERVER['REQUEST_URI']);
$searchStr = isset($arr[1]) ? addslashes(urldecode(trim($arr[1]))) : '';

echo '<form method="get" action="'. base_url() . 'blog/search/">'
."Search for phrase:<br />" 
."&lt;input type='text' name='s' value='$searchStr'&gt;"
. "<br />"
.'&lt;input type="submit" Search&gt;';


/*
rest of code goes here
... find data in database and display it
*/

} [/code]

Clone this wiki locally