NameSilo

Mysql pagination help needed, NP$25 for help

Spaceship Spaceship
Watch

khuldun

Established Member
Impact
18
Now here is the quesry i am working on

mysql_query("select count(*) from table");

Basically, i have a table with a ciolumn for categories. Without makign anew page, i am using the if function to list all the rows of a particular column. Its going on alright but when it comes to paging the results, it returns the total pages of the entire table and not that particular column and if you clikc on any page number, it moves to a page with all the categories instaead of remaining on the same category. Basically i am trying to do something on these lines

mysql_query("select count(*) from table where cat=$cat");

the cat is variable and can be defined as $_GET, but its not working. Can anyone help me please? I need to paginate my results wiuth respect to columns in the table.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
I'm not sure exactly what you're using here but it sounds like your '$cat' variable is not being interpolated. Maybe you can do something like:
Code:
$query = 'select count(*) from table where cat=' . $cat;

mysql_query($query);
Of course, syntax depends on the language.

Good luck.
-Nitro
 
0
•••
There are no quotes around $cat which could cause problems (also I hope you are sanitizing the variable before you are using it):-

PHP:
mysql_query("select count(*) from table where cat='$cat'");

also try echoing out the query to ensure that it looks right and try that query in phpmyadmin to ensure that it has the desired effect.

Nitroshock said:
I'm not sure exactly what you're using here but it sounds like your '$cat' variable is not being interpolated. Maybe you can do something like:
Code:
$query = 'select count(*) from table where cat=' . $cat;

mysql_query($query);
Of course, syntax depends on the language.

Good luck.
-Nitro

The code is php as the mysql_query is a php function. There is no reason to use a variable for the query nor any reason to concatanate the query. Your code will have the same affect as what he already has.
 
Last edited:
0
•••
PHP:
<?php
$cat = mysql_escape_string($_GET['cat']);
$page = 1;
mysql_query("select count(*) from table where cat='".$cat."' limit ".(($page-1)*25).",25");
?>
That will put 25 results on each page.
 
0
•••
when you open the page, by default it does not have a ?cat page, it simply opens the .php page, so if i set $cat here, how can i make it point to all categories when $cat == ""? First porblem still not resolved:(
 
0
•••
PHP:
$cat = (!isset($_GET['cat'])) ? 'all categories' : mysql_real_escape_string($_GET['cat']);
 
0
•••
khuldun said:
when you open the page, by default it does not have a ?cat page, it simply opens the .php page, so if i set $cat here, how can i make it point to all categories when $cat == ""? First porblem still not resolved:(

did you try what I suggested? if so what did the output query look like and did it work in phpmyadmin?
 
0
•••
Thanks Second version, that was excetly what i was looking for, hit the nail right on the head!
 
0
•••

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back