php paging

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
prasaderandi
Forum Newbie
Posts: 10
Joined: Fri Jul 01, 2005 1:09 pm

php paging

Post by prasaderandi »

i wrote a php coding but its not working if i'm using where
clause can u help me whats wrong

Code: Select all

function coding is function pc_print_link($inactive,$text,$offset='')
{
if($inactive)
{
printf('<font color="#666666">%s</font>',$text);
}
else
{
printf('<a href="%s?offset=%d">%s</a>',$_SERVER['PHP_SELF'],$offset,$text);
}
}// end of function


function pc_indexed_links($total,$offset,$perpage)
{
$separator='|';
//print prev link

pc_print_link($offset==1,'<<Prev',$offset-$perpage);
//print all groupings except last one
for($start=1,$end=$perpage;$end<$total;$start+=$perpage,$end+=$perpage)
{

print $separator;
pc_print_link($offset==$start,"$start-$end",$start);

}
//end for loop
$end=($total > $start)?"-$total":'';
print $separator;
pc_print_link($offset==$start,"$start$end",$start);
//print next >> link
print $separator;


pc_print_link($offset==$start,'Next>>',$offset+$perpage);

}

my sql statement is

Code: Select all

select * from friend where age=$age and sex='$seek';
but if i remove where clause its working proprly. help me

JCART | Please use

Code: Select all

tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Sphen001
Forum Contributor
Posts: 107
Joined: Thu Mar 10, 2005 12:24 pm
Location: Land of the Beaver

Post by Sphen001 »

Hi,

Try removing the quotes from around the variable $seek.

Code: Select all

SELECT *
  FROM friends
    WHERE age=$age
    AND sex=$seek
Hope this helps :D

Sphen001
prasaderandi
Forum Newbie
Posts: 10
Joined: Fri Jul 01, 2005 1:09 pm

Post by prasaderandi »

no its not working. but if i put sex='Male',age=30; like hard coding its working propely.
Sphen001
Forum Contributor
Posts: 107
Joined: Thu Mar 10, 2005 12:24 pm
Location: Land of the Beaver

Post by Sphen001 »

That's weird.

Are you sure that there is a value inside the variable?

Maybe post part of the code that assigns the values $seek, and $age.

Thanks

Sphen001
prasaderandi
Forum Newbie
Posts: 10
Joined: Fri Jul 01, 2005 1:09 pm

Post by prasaderandi »

no. i think problem is i cant to pick up values when its posting.(PHP_SELF) coding has hyperlink i'll try to edit that coding but its not supporting. this is a hyperlink
i have to edit

Code: Select all

printf('<a href="%s?offset=%d">%s</a>',$_SERVER['PHP_SELF'],$offset,$text);
how can i insert age value to this hyper link. i try to use like this but its not working.

Code: Select all

printf('<a href="%s?offset=%d&age=$age">%s</a>',$_SERVER['PHP_SELF'],$offset,$text);
JCART | Please use

Code: Select all

tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
prasaderandi
Forum Newbie
Posts: 10
Joined: Fri Jul 01, 2005 1:09 pm

error

Post by prasaderandi »

error showing
You have an error in your SQL syntax near 'and age>=)' at line 1
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Start using

Code: Select all

tags!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

First of all, variables are not parsed in single quotes, so either change the single quotes the double quotes or escape the quotes when you want to parse the variable. Since your using sprintf might aswell use that to do it though.

Code: Select all

printf('<a href="%s?offset=%d&age=%d">%s</a>',$_SERVER['PHP_SELF'],$offset,$age,$text);
Last edited by John Cartwright on Fri Jul 01, 2005 2:49 pm, edited 1 time in total.
prasaderandi
Forum Newbie
Posts: 10
Joined: Fri Jul 01, 2005 1:09 pm

Post by prasaderandi »

i remove single qutes and insert double quates but its not working what u write hyper link i think its useful me to develop the code thank u
prasaderandi
Forum Newbie
Posts: 10
Joined: Fri Jul 01, 2005 1:09 pm

Post by prasaderandi »

and what is %s and %d
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

sprintf wrote:A type specifier that says what type the argument data should be treated as. Possible types:


% - a literal percent character. No argument is required.
b - the argument is treated as an integer, and presented as a binary number.
c - the argument is treated as an integer, and presented as the character with that ASCII value.
d - the argument is treated as an integer, and presented as a (signed) decimal number.
e - the argument is treated as scientific notation (e.g. 1.2e+2).
u - the argument is treated as an integer, and presented as an unsigned decimal number.
f - the argument is treated as a float, and presented as a floating-point number (locale aware).
F - the argument is treated as a float, and presented as a floating-point number (non-locale aware). Available since PHP 4.3.10 and PHP 5.0.3.
o - the argument is treated as an integer, and presented as an octal number.
s - the argument is treated as and presented as a string.
x - the argument is treated as an integer and presented as a hexadecimal number (with lowercase letters).
X - the argument is treated as an integer and presented as a hexadecimal number (with uppercase letters).
Show me your code. And please use the edit button rather than posting multiple posts in a row
prasaderandi
Forum Newbie
Posts: 10
Joined: Fri Jul 01, 2005 1:09 pm

Post by prasaderandi »

i'm using this code but its not working why is that

Code: Select all

$age_now=intval($_REQUEST('age1');
$age_now showing 0. what i want to do is i'm using PHP_SELF
.so i need to keep ths $age value as temperaly.
d11wtq | .. [ php] tags please
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Missing a parentheses and also, array use square barckets like this:

Code: Select all

$age_now=intval($_REQUEST['age1']);
Post Reply