Current location: Hot Scripts Forums » Programming Languages » PHP » need help simple question, but need it right.


need help simple question, but need it right.

Reply
  #1 (permalink)  
Old 01-28-06, 07:43 PM
0o0o0 0o0o0 is offline
Wannabe Coder
 
Join Date: Jul 2005
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
need help simple question, but need it right.

ok this is simple. well sounds simple.. but I just want it to be 100% correct from the start.

I have 6 photo PAGES.

6 photos on 6 single pages.

I have PREVIOUS and NEXT buttons at the bottom.

ive tried my own attempt at this and I get blank screen.

So..

what im trying to do is make page 1.. if I hit next..
it goes to page 2.. ( simple enough current page+2) But!
on page one if I hit previous ..I want it to add 5 to make it 6 and go to page 6.

lol now im confusing myself.

heres what i tried..

IF ($pg_num>6) {
$pg= (1)};

and
If ($pg_num<1){
$pv=(6)};

so more or less if your on page 1 and hit previous.. it "should" take you to page 6

and if your on page 6 and hit next.. it "should" take you back to page 1

wheres my error? or does anyone have a simpler easier method for me.

thanks.

--- Well edited this one before anyone answered..

can someone check this for me and tell me if its safe to use and logical..
It works fine for what im looking for just need some input.

thanks.

IF ($Pg_Num >= 6) {
$pg= '1';
} else {
$pg = $Pg_Num + 1;
}

IF ($Pg_Num <= 1) {
$pv= '6';
} else {
$pv = $Pg_Num - 1;
}

lemme know if thats safe and logical.

Last edited by 0o0o0; 01-28-06 at 08:17 PM.
Reply With Quote
  #2 (permalink)  
Old 01-28-06, 08:12 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Try this sample code -
PHP Code:

<?php

// pages are numbered 1 through max_page
$max_page 6;

for (
$cur_page 1$cur_page <= $max_page$cur_page++) {

$next_page $cur_page 1;
if (
$next_page $max_page) {
    
$next_page 1;
}
$prev_page $cur_page 1;
if (
$prev_page 1) {
    
$prev_page $max_page;
}
echo 
"Prev: $prev_page, Current: $cur_page, Next: $next_page<br>";
}
?>
Basically, the next page is always one more than the current page. When it becomes greater than the maximum (6 in your case) wrap this around to the starting page. Going the other direction, the previous page is always one less than the current page. When it becomes less than the starting page (1) wrap this around to the maximum page.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #3 (permalink)  
Old 01-28-06, 08:18 PM
0o0o0 0o0o0 is offline
Wannabe Coder
 
Join Date: Jul 2005
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
thanks! is this safe tho?? its already in my script.

IF ($Pg_Num >= 6) {
$pg= '1';
} else {
$pg = $Pg_Num + 1;
}

IF ($Pg_Num <= 1) {
$pv= '6';
} else {
$pv = $Pg_Num - 1;
}

lemme know.
Reply With Quote
  #4 (permalink)  
Old 01-31-06, 04:21 PM
Sheepymot's Avatar
Sheepymot Sheepymot is offline
Newbie Coder
 
Join Date: Jan 2006
Location: England
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Yes that appears to be correct code.

Although the script MAB posted is more efficient
__________________
PHPGurus - Free PHP Help
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple mySQL Question, Multiplying Entire Column Luke2 PHP 2 07-21-05 08:00 PM
Simple question Maniax JavaScript 4 08-31-04 01:08 PM
Simple PHP question about JPEG? snooky5 PHP 4 08-14-04 03:36 PM
Simple question kashi PHP 5 08-13-04 10:23 PM
question about simple login system magsec4 PHP 5 02-23-04 03:35 AM


All times are GMT -5. The time now is 06:29 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.