Jump to content

Duplicate Data in Output


smithmr8

Recommended Posts

Hi,

http://www.bytefish.co.uk/client_DFC/products.php?page=1&sort=B

 

Trying to get it to list the items which begin with the letter B. It does this to some degree. However, as you get a couple pages into it it keeps displaying the same data.

 

Here is the PHP:

if($_GET['sort'] == ""){
$all = mysql_num_rows(mysql_query("SELECT * FROM `products`"));
} else {
$sort = $_GET['sort'];
$all = mysql_num_rows(mysql_query("SELECT * FROM `products` WHERE `name` LIKE '$sort%'"));
echo $all;
}

if ($all % 50 != 0){
$remainder = ($all - ($all % 50));
$total = ($remainder / 50)+1;
} else {
$total = ($all / 50);
}
if ($_GET['page'] > 0){
$page = $_GET['page'];
} else {
$page = 1;
}
$upper = $page * 50;
$lower = ($page - 1) * 50;
if($_GET['sort'] == ""){
$products = mysql_query("SELECT * FROM `products` LIMIT $upper, $lower");
} else {
echo $lower;
echo $upper;
$products = mysql_query("SELECT * FROM `products` WHERE `name` LIKE '$sort%' LIMIT $lower, $upper");
}

 

Any ideas ?

Link to comment
https://forums.phpfreaks.com/topic/207180-duplicate-data-in-output/
Share on other sites

Solved. lol.

 

Did this instead..

 

//$upper = $page * 50;
$lower = ($page - 1) * 50;

if($_GET['sort'] == ""){
$products = mysql_query("SELECT * FROM `products` LIMIT $lower, 50");
} else {
echo $lower;
echo $upper;
$products = mysql_query("SELECT * FROM `products` WHERE `name` LIKE '$sort%' LIMIT $lower, 50");
}

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.