jj20051 Posted February 25, 2009 Share Posted February 25, 2009 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 More sharing options...
jj20051 Posted February 25, 2009 Author Share Posted February 25, 2009 I'm still having problems Link to comment https://forums.phpfreaks.com/topic/146805-solved-pagination-help/#findComment-770834 Share on other sites More sharing options...
jj20051 Posted February 25, 2009 Author Share Posted February 25, 2009 3.5 hours of searching google + the help of friends... my god!! Link to comment https://forums.phpfreaks.com/topic/146805-solved-pagination-help/#findComment-770872 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.