Jump to content

[SOLVED] Pagination Help!!


jj20051

Recommended Posts

I've tried several times to paginate a PHP Search script that I have written ( A few people did help me ). The problem is I can't seem to do it without creating 2 separate queries, or without getting 5 MYSQL errors back ( Joking On The 5 Part )... So some help would be greatly appreciated.

 

<?php
include ('config.php');

$search = $_GET['search'];

if ($search == NULL){

echo '<center><strong>You Didn\'t Type Anything In!</center></strong>';

} 
else { 

// Search Keywords Define
$search = $search . " "; // add a space so in case of 1 word this should work.
$searchArr = explode(" ", $search); // split variables into separate words.
$search = array();
foreach ($searchArr as $keyword) {
    if (!empty($keyword)) {
         $search[] = "`keywords` LIKE '%{$keyword}%'";
   }
}
if (count($search) > 1)
    $search = "(" . implode(" AND ", $search) . ")";
else
    $search = $search[0]; // no need for the implode.

// Query
$query = "SELECT * FROM sites WHERE {$search} ORDER BY totalrating DESC";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
// Shorten Description
$yourtext = $row['description'];
$title = $row['title'];
$url = $row['url'];
if ( strlen( $yourtext ) > 45 ) {
   $yourtext = explode( ' ',$yourtext );
   $yourtext = array_slice( $yourtext, 0, 45 );
   $yourtext = implode( ' ', $yourtext) . ' ...';
} 
else {
}
// Shorten Title
if ( strlen( $title ) > 11 ) {
   $title = explode( ' ',$title );
   $title = array_slice( $title, 0, 11 );
   $title = implode( ' ', $title) . ' ...';
}
else {
}
// Display Results
echo '<table border="0" class="sample">';
echo '<tr><td><strong><a href='.$url.'><font size="2">';
echo $title;
echo '</font></a></strong></td></tr>';
echo '</table>';
echo '<table width="580" border="0" class="sample">';
echo '<tr><td><font size="2">';
echo $yourtext;
echo '</font></td></tr><tr><td><font color="green" size="2">';
echo $url;
echo '</font></td></tr></table></font><br>';
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/146805-solved-pagination-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.