I create my own searching at my website and I have create page search result page which contains <php>
code, I use plugin PHP-Exec at my search result page. I create pagination, but it seems not work properly.
When I click "Next" for next result of my own searching the url parameter is redirect to wrong url.
The Url should be :
http://inindonesia.org/hasil-pencarian?phrase=sofa+bed&page=1
But, it redirect to :
http://inindonesia.org/hasil-pencarian/1?phrase=sofa bed
It is wrong URL exactly, and I feel stuck because automatically it can affect the search results of my own search :( . For information, I use Wordpress Multisite, any ideas for keeping my URL parameter?
Here my code :
<?php
$dbhost = 'myhost';
$dbuser = 'mydbuser';
$dbpass = 'mydbpass';
$hasil = $_GET[phrase];
$type = str_replace(' ','+',$hasil);
$rec_limit = 2;
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ){
die('Database tidak terkoneksi' . mysql_error());
}
mysql_select_db('mydb');
$sql = "SELECT count(wp_mp_term_relationships.post_id) FROM `wp_mp_term_relationships` INNER JOIN wp_mp_products ON wp_mp_products.id = wp_mp_term_relationships.post_id INNER JOIN wp_mp_terms ON wp_mp_terms.term_id = wp_mp_term_relationships.term_id WHERE wp_mp_terms.name = '$hasil'";
$retval = mysql_query( $sql, $conn );
if(! $retval ){
die('Tidak dapat Menerima Data: ' . mysql_error());
}
$row = mysql_fetch_array($retval, MYSQL_NUM );
$rec_count = $row[0];
if( isset($_GET{'page'} ) ){
$page = $_GET{'page'} + 1;
$offset = $rec_limit * $page ;
}else{
$page = 0;
$offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);
$query = "SELECT * FROM `wp_mp_term_relationships` INNER JOIN wp_mp_products ON wp_mp_products.id = wp_mp_term_relationships.post_id INNER JOIN wp_mp_terms ON wp_mp_terms.term_id = wp_mp_term_relationships.term_id WHERE wp_mp_terms.name = '$hasil' LIMIT $offset, $rec_limit";
$query_retval = mysql_query( $query, $conn );
if(! $query_retval ){
die('Tidak dapat menerima data ' . mysql_error());
}
while($result = mysql_fetch_array($query_retval, MYSQL_ASSOC)) {
echo "<h3><a href=" . $result[post_permalink] . " target=_blank>" . $result[post_title] . "</a></h3>";
$content = $result[post_content];
$content_len = strlen($content);
if ( $content_len > 150 ){
echo "<div style='margin-left: 26px; margin-top: 6px; margin-bottom: -26px;'><h3 style='font-size: 13px; line-height: -0.5'>" . substr($content, 0, 150) . " ...<a href=" . $result[post_permalink] . " target=_blank> (more)</a></h3></div>";
}else{
echo "<div style='margin-left: 26px; margin-top: 6px; margin-bottom: -26px;'><h3 style='font-size: 13px; line-height: -0.5'>" . $content . "</h3></div>";
}
echo "<hr>";
}
if( $page > 0 ){
$last = $page - 1;
echo "<a href=\"$_PHP_SELF?phrase=$type&page=$last\">Last 5 Records</a> |";
echo "<a href=\"$_PHP_SELF?phrase=$type&page=$page\">Next 5 Records</a>";
}else if( $page == 0 ){
echo "<p>" . $_PHP_SELF . "?phrase=" . $type . "&page=" . $page . "</p>";
echo "<a href=\"$_PHP_SELF?phrase=$type&page=$page\">Next 5 Records</a>";
}else if( $left_rec < $rec_limit ){
$last = $page - 1;
echo "<a href=\"$_PHP_SELF?phrase=$&page=$last\">Last 5 Records</a>";
}
mysql_close($conn);
?>