/    Sign up×
Community /Pin to ProfileBookmark

Picture navigation

Hi All

I have made a photo album.currently the photos are displayed like the following way in (pic.php):

Picture 1 Picture 2 Picture 3
(ID=1,Pos=1) (ID=2,Pos2) (ID=3,Pos=3)

Picture 4 Picture 5 Picture 6
(ID=4,Pos=4) (ID=5,Pos5) (ID=6,Pos=6)

Picture 7 Picture 8 Picture 9
(ID=7,Pos=7) (ID=8,Pos8) (ID=9,Pos=9)

Now if I click say Picture 5 then its showing in another page(viewpic.php).

Now in viewpic.php I want to display the photos in this way:

Picture 3 Picture 4 Picture 5 Picture 6 Picture 7

Picture 5

I am getting the position of each pic from mysql by this query

[code=php]$s=”select count(pic_id) as p from album where pic_id<=’$pic_id'”;[/code]

and in viewpic.php I have made a if else condition like

if($pos==1)
{
$sp=1;//start position of the row
$ep=5;//end position of the row
}
else
{
$sp=$pos-2;
$ep=$pos+2;
}
and running this query to make the above display

[code=php]$s1=”select * from album limit $sp,$ep “;[/code]

But this is not working at all….

Could you please tell me what should I do now….I am close to the display but not happening to my satisfaction.

Thanks in advance for your co-operation….Raj

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@michael879Sep 14.2007 — well you should tell us what exactly isnt working. However, from what I can see, I can tell you 1 mistake in ur code. The format for LIMIT in mysql is:
[CODE]LIMIT offset, count[/CODE]

therefore instead of
[code=php]
if($pos==1)
{
$sp=1;//start position of the row
$ep=5;//end position of the row
}
else
{
$sp=$pos-2;
$ep=$pos+2;
}
[/code]

use
[code=php]
if($pos<=3)
$sp=0; //start position of the row
else
$sp=$pos-3;
$ep=5; //number of pictures
[/code]


you should also add in
[CODE]ORDER BY pic_id ASC[/CODE]
just to make sure its in the right order.
Copy linkTweet thisAlerts:
@raj_2006authorSep 14.2007 — Hi

Thanks for your suggestion.The number of images per page is not working correctly.Sometimes it is showing 6 sometimes it is showing 3....I think the if else condition need to be correct.Basically my logic is something like this:

if $pos==1 then display first 5 images

if $pos==2 then display 1,2,3,4,5 images

if $pos==3 then display 1,2,3,4,5 images

if $pos==4 then display 2,3,4,5,6 images

....and so on

now if the $pos==total number of rows returned by the query(if it is say x) then display x-1,x-2,x-3,x-4,x-5 images...I mean last 5 images

thats it.....

now according to your views....$pos==offset(If i am not wrong)

Now if i put the above equation into the if else condition then hope it stands like this:

[code=php]if($pos==1 or $pos==2 or $pos==5)
{
$sp=0;
$ep=5;
}
else if($pos==$total_num_rows)
{
//here how the images will be fetched?
}
else//means if the $pos is greater than 3 and less than total num of rows
{
$sp=$pos;
$ep=$pos-5;
}[/code]

I am displaying the images in a single <td>....

Please suggest me if my above if else condition is right or wrong....

Thanks

Raj
Copy linkTweet thisAlerts:
@michael879Sep 14.2007 — what? I dont understand your last post at all. LIMIT takes two parameters. The first one is the offset and the second is the count. You always want the count to be 5. You want the offset to be 0 if the $pos is 1, 2 or 3. Otherwise you want the offset to be $pos-3.

$ep should ALWAYS be 5. $sp should be $pos-3 unless $pos-3 < 0 in which case $sp = 0.
Copy linkTweet thisAlerts:
@michael879Sep 14.2007 — o yea, and if $pos > $total_num_rows-3

make $sp = $total_num_rows-5

and keep $ep = 5
Copy linkTweet thisAlerts:
@raj_2006authorSep 14.2007 — Hi

Thanks mate....Its working.Here is the if else condition part

[code=php]if($pos<=3)
{
$sp=0;
$ep=5;
}
else if($pos>$t1-3)
{
$sp=$t1-5;
$ep=5;
}
else
{
$sp=$pos-2;
$ep=5;
}
$s1="select * from album where cid='{$_GET['cid']}' and aid='{$_GET['aid']}' order by pic_id asc limit $sp,$ep ";[/code]


Here another thing I want to do is to keep a Next page|Prev Page link

In a single page there are total 5 images...

Can you please tell me how can I make a start....the basic logic is............. on getting the page number(there will be no page number by default in the 1st page) from next page it will be 2...and so on...also it will be checked by the total number of rows/5(as i want to keep 5 per page).....any hints will be helpful to me...

Thanks

Raj
Copy linkTweet thisAlerts:
@michael879Sep 17.2007 — just make $pos = $initial_pos + 5*$page

where $page = 0 on the first page.
Copy linkTweet thisAlerts:
@raj_2006authorSep 20.2007 — Hi

Sorry to reply in late.

should I put the

just make $pos = $initial_pos + 5*$page

where $page = 0 on the first page.[/QUOTE]


inside the if-else condition and also from where the $page is coming.I assume from $_GET

Raj
Copy linkTweet thisAlerts:
@michael879Sep 21.2007 — that should go before the if-else statement. Basically its taking advantage of your old setup to allow for pages. $initial_pos is the old $pos, which should be passed along through $_GET between pages. $page can be determined however you want but I would do it through $_GET also.
×

Success!

Help @raj_2006 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...