[advanced search]
Results from the most recent live auction are here.
20 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming
User Name
Password

Old 04-08-2006, 12:56 PM   · #1
khuldun
Senior Member
 
Name: Khuldun Jatala
Location: Lahore, Pakistan
Trader Rating: (7)
Join Date: Oct 2005
Posts: 1,108
NP$: 12.40 (Donate)
khuldun has a spectacular aura aboutkhuldun has a spectacular aura about
mysql pagination help needed, NP$25 for help

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.


Please register or log-in into NamePros to hide ads
__________________
New mobile content website coming soon
khuldun is offline   Reply With Quote
Old 04-08-2006, 01:54 PM   · #2
Nitroshock
NamePros Regular
 
Nitroshock's Avatar
 
Trader Rating: (55)
Join Date: Mar 2005
Posts: 502
NP$: 362.00 (Donate)
Nitroshock is a splendid one to beholdNitroshock is a splendid one to beholdNitroshock is a splendid one to beholdNitroshock is a splendid one to beholdNitroshock is a splendid one to beholdNitroshock is a splendid one to beholdNitroshock is a splendid one to behold
Child Abuse Third World Education
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
__________________
Bored? Play FREE Games
Nitroshock is offline   Reply With Quote
Old 04-08-2006, 01:54 PM   · #3
Peter
NamePros Staff
 
Peter's Avatar
 
Name: Peter
Location: Scotland
Trader Rating: (47)
Join Date: Nov 2003
Posts: 4,337
NP$: 2039.40 (Donate)
Peter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud of
Child Abuse Save The Children Save The Children
There are no quotes around $cat which could cause problems (also I hope you are sanitizing the variable before you are using it):-

PHP Code:
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.

Originally Posted by Nitroshock
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 by filth@flexiwebhost : 04-08-2006 at 01:59 PM.
Peter is offline   Reply With Quote
Old 04-08-2006, 02:32 PM   · #4
Jim_
NamePros Regular
 
Jim_'s Avatar
 
Name: Jim, of course
Location: Philadelphia
Trader Rating: (20)
Join Date: Aug 2005
Posts: 558
NP$: 14.30 (Donate)
Jim_ is a glorious beacon of lightJim_ is a glorious beacon of lightJim_ is a glorious beacon of lightJim_ is a glorious beacon of lightJim_ is a glorious beacon of light
Save The Children
PHP Code:
<?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.
__________________
woop woop
Jim_ is offline   Reply With Quote
Old 04-08-2006, 02:41 PM   · #5
khuldun
Senior Member
 
Name: Khuldun Jatala
Location: Lahore, Pakistan
Trader Rating: (7)
Join Date: Oct 2005
Posts: 1,108
NP$: 12.40 (Donate)
khuldun has a spectacular aura aboutkhuldun has a spectacular aura about
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
__________________
New mobile content website coming soon
khuldun is offline   Reply With Quote
Old 04-08-2006, 03:01 PM   · #6
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 
Name: Eric
Location: Kentucky
Trader Rating: (142)
Join Date: Mar 2005
Posts: 4,268
NP$: 1152.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
Member of the Month
MOTM September 2005 Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet
PHP Code:
$cat = (!isset($_GET['cat'])) ? 'all categories' : mysql_real_escape_string($_GET['cat']);
__________________

SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.3 now available!!
SecondVersion is offline   Reply With Quote
Old 04-08-2006, 04:54 PM   · #7
Peter
NamePros Staff
 
Peter's Avatar
 
Name: Peter
Location: Scotland
Trader Rating: (47)
Join Date: Nov 2003
Posts: 4,337
NP$: 2039.40 (Donate)
Peter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud of
Child Abuse Save The Children Save The Children
Originally Posted by khuldun
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?
Peter is offline   Reply With Quote
Old 04-10-2006, 03:37 PM   · #8
khuldun
Senior Member
 
Name: Khuldun Jatala
Location: Lahore, Pakistan
Trader Rating: (7)
Join Date: Oct 2005
Posts: 1,108
NP$: 12.40 (Donate)
khuldun has a spectacular aura aboutkhuldun has a spectacular aura about
Thanks Second version, that was excetly what i was looking for, hit the nail right on the head!
__________________
New mobile content website coming soon
khuldun is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Site Sponsors
RealTechNetwork EscrowDNS Hunting Moon
Advertise your business at NamePros
All times are GMT -7. The time now is 09:24 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0