I’ve built a code that allows searching of a database, but for some reason integrating the pagination part of it I was unable to get the search box to work with it. I am not sure where to even insert the code for it. The variable or search term will be passed in the URL like for any search function. But I am stumped. Here’s my source code.
[php]
<?php $connection=mysql_connect('127.0.0.1','XXXXXX','XXXXXX'); if(!$connection) { echo 'connection is invalid'; } else { mysql_select_db('XXXXXX',$connection); } //check if the starting row variable was passed in the URL or not if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) { //we give the value of the starting row to 0 because nothing was found in URL $startrow = 0; //otherwise we take the value from the URL } else { $startrow = (int)$_GET['startrow']; } //this part goes after the checking of the $_GET var $fetch = mysql_query("SELECT * FROM songdb ORDER BY artist LIMIT $startrow, 10")or die(mysql_error()); $num=Mysql_num_rows($fetch); if($num>0) { for($i=0;$i<$num;$i++) { $row=mysql_fetch_row($fetch); ?>
<?php echo $row[1]; ?>
<?php echo $row[2]; ?>
<?php }}
//only print a "Previous" link if a "Next" was clicked
if ($prev >= 0)
echo ' Previous';
//now this is the link..
echo ' Next';
<?php echo $row[2]; ?>
$prev = $startrow - 10;
?>
[/php]Any ideas?