Have an account? Sign in
Login  Register  Facebook
problem using Awesome PHP/MySQL Pagination solution
I thought the solution (http://www.awcore.com/dev/1/3/Create-Awesome-PHPMYSQL-Pagination_en) posted on awcore.com fit my purpose neatly; however, there is a problem which I cannot resolve. I am working on a database of names, and I try to pass a search term from a form into a mysql select string to retrieve the names using certain letters in the names as seaerch criteria and then display them paginated with 16 on a page, but the result returned is correct for the first page, but subsequent pages contain names not queried. When I hard code like '%D%' in the query string, I can get the query result right. I have modified the url variable in function.php from '$url=?' to '$url=/page/index.php?' to reflect the site structure. Should appreciate any help for a problem that has been bugging me for days. Here is the code for my index.php, on which the names are displayed.
<?php
//connect to the database
include_once ('db.php');
//get the function
include_once ('function.php');

$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
$limit = 16;
$startpoint = ($page * $limit) - $limit;

if (isset($_POST['submitted'])) {
$var = $_POST['searchTerm'];
}

//to make pagination
$statement = "`records` where `name` like '%".$var."%'";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Pagination</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link href="css/pagination.css" rel="stylesheet" type="text/css" />
<link href="css/grey.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.records {
width: 510px;
margin: 5px;
padding:2px 5px;
border:1px solid #B6B6B6;
}

.record {
color: #474747;
margin: 5px 0;
padding: 3px 5px;
background:#E6E6E6;
border: 1px solid #B6B6B6;
cursor: pointer;
letter-spacing: 2px;
}
.record:hover {
background:#D3D2D2;
}


.round {
-moz-border-radius:8px;
-khtml-border-radius: 8px;
-webkit-border-radius: 8px;
border-radius:8px;
}

p.createdBy{
padding:5px;
width: 510px;
font-size:15px;
text-align:center;
}
p.createdBy a {color: #666666;text-decoration: none;}
</style>
</head>

<body>

<div class="records round">Search for : <?php echo $var;?></div>
<div class="records round">
<?php
//show records
$query = mysql_query("SELECT * FROM {$statement} LIMIT {$startpoint} , {$limit}");

while ($row = mysql_fetch_assoc($query)) {
?>
<div class="record round"><?php echo "{$row['id']}--{$row['name']}";?></div>
<?php
}
?>
</div>

<?php
echo pagination($statement,$limit,$page);
?>

</body>
</html>
Started: April 2, 2012 Latest Activity: April 2, 2012 pagination querystring
1 Answer
if you want to use the first char
WHERE RIGHT(colname,1) = 'b'

Posted: MacOS
In: April 2, 2012

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer