Page 1 of 1
php paging
Posted: Fri Jul 01, 2005 1:20 pm
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]
Posted: Fri Jul 01, 2005 1:29 pm
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
Sphen001
Posted: Fri Jul 01, 2005 1:33 pm
by prasaderandi
no its not working. but if i put sex='Male',age=30; like hard coding its working propely.
Posted: Fri Jul 01, 2005 1:35 pm
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
Posted: Fri Jul 01, 2005 1:42 pm
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]
error
Posted: Fri Jul 01, 2005 1:44 pm
by prasaderandi
error showing
You have an error in your SQL syntax near 'and age>=)' at line 1
Posted: Fri Jul 01, 2005 2:20 pm
by John Cartwright
Posted: Fri Jul 01, 2005 2:22 pm
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);
Posted: Fri Jul 01, 2005 2:38 pm
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
Posted: Fri Jul 01, 2005 2:39 pm
by prasaderandi
and what is %s and %d
Posted: Fri Jul 01, 2005 2:51 pm
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
Posted: Sat Jul 02, 2005 12:06 pm
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
Posted: Sat Jul 02, 2005 12:12 pm
by Chris Corbyn
Missing a parentheses and also, array use square barckets like this:
Code: Select all
$age_now=intval($_REQUEST['age1']);