Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-25-2006, 02:59 PM This should be easy
Super Talker

Posts: 102
Trades: 0
Hi,

As I'm building this photogallery system, I'd like to build in a sort of navigation bar with which you can jump back and forth pics and jump back to the index.

It basically works like this;
<< Previous | Next >> Back to index

Where previous should jump to the previous picture and next to the next
Back to index can just be a link back to index.php. I have absolutely no scripting experience I don't have a clue how to build something like this, but I figure this should be pretty easy to make. Who can help me ?

The files are all listed in an ascending order. Like DSC00227.jpg, DSC00228.jpg, DSC00229.jpg, DSC00230.jpg etc.

Help will be much appreciated
ghettobert is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-25-2006, 03:30 PM Re: This should be easy
Skilled Talker

Posts: 68
Trades: 0
PHP Code:
<?
$img 
$GET_['id'];
$nxt $img++;
$prv $img--;
if (isset(
$img) )  
{
echo 
"<img scr=DSC00$img >";
echo 
"<BR>";
echo 
"<a href=file/file.php?id=$pre>Previous";
echo 
"<a href=file/file.php?id=$nxt>Next";
} else {
$img "227";
$nxt $img++;
$prv $img--;
echo 
"<img scr=DSC00$img >";
echo 
"<BR>";
echo 
"<a href=file/file.php?id=$pre>Previous";
echo 
"<a href=file/file.php?id=$nxt>Next";
}
That would be a easy way.. Please check "$prev = $img--" becasue i think i might of just made that up, if it dosent work then $prev needs to be one less that the num.
I'm sure you can figure that out??
__________________
Need PHP Help? Got Skype?
Call me!
mrpaul is offline
Reply With Quote
View Public Profile
 
Old 04-25-2006, 03:52 PM Re: This should be easy
Super Talker

Posts: 102
Trades: 0
At the moment it doesn't really work.

I understand the script echoes an image which starts with the variable $img.

$img is set to 227. And if you click next it simply adds 1 to that 227 and for previously it subtracts 1. Is it ok that the .jpg extension is nowhere to be found btw ?

How should I have set up my folders ? Do the images go in a seperate folder how should I call the actual PHP file itself ?

edit
$prv = $img--;
echo "<a href=file/file.php?id=$pre>

I take it the $pre here is a typo and should be the $prv right ?

Last edited by ghettobert; 04-25-2006 at 04:03 PM..
ghettobert is offline
Reply With Quote
View Public Profile
 
Old 04-25-2006, 04:01 PM Re: This should be easy
Skilled Talker

Posts: 68
Trades: 0
PHP Code:
<? 
$img 
$GET_['id']; 
$nxt $img++; 
$prv $img--; 
if (isset(
$img) )   

echo 
"<img scr=DSC00$img.jpg >"
echo 
"<BR>"
echo 
"<a href=/img/file.php?id=$pre>Previous"
echo 
"<a href=/img/file.php?id=$nxt>Next"
} else { 
$img "227"
$nxt $img++; 
$prv $img--; 
echo 
"<img scr=DSC00$img.jpg >"
echo 
"<BR>"
echo 
"<a href=/img/file.php?id=$pre>Previous"
echo 
"<a href=/img/file.php?id=$nxt>Next"
}
?>
Yeah you need the .jpg.
For the imges just creat one folder "img" and make sure ther set out how you said they were.

Edit: Yes typeo sorry =0
__________________
Need PHP Help? Got Skype?
Call me!

Last edited by mrpaul; 04-25-2006 at 04:12 PM..
mrpaul is offline
Reply With Quote
View Public Profile
 
Old 04-25-2006, 05:36 PM Re: This should be easy
Super Talker

Posts: 102
Trades: 0
I just updated the script. But it's still not working. Any thoughts on what might be wrong ?

In the browseradress bar is the following url;
/images/test.php?id=

Not Found
The requested URL was not found on this server.

Last edited by ghettobert; 04-25-2006 at 05:45 PM..
ghettobert is offline
Reply With Quote
View Public Profile
 
Old 04-25-2006, 05:51 PM Re: This should be easy
Skilled Talker

Posts: 68
Trades: 0
test.php should be outside of /images brcasue now test.php is looking for the folder /images in /images
__________________
Need PHP Help? Got Skype?
Call me!

Last edited by mrpaul; 04-25-2006 at 05:53 PM..
mrpaul is offline
Reply With Quote
View Public Profile
 
Old 04-25-2006, 06:05 PM Re: This should be easy
cdwhalley.com's Avatar
Skilled Talker

Posts: 75
Trades: 0
Save this as file.php, in the same place as all the images.
I've corrected mrpaul's code, and made it into xhtml, because (no offence) it was full of errors.
PHP Code:
<?php
if (isset($_GET['id']) && $_GET['id'] > 227){  //if the id is set and its not 227
    
$previous $_GET['id'] - 1;//make the id for the previous image
    
$next       $_GET['id'] + 1;//make the id for the next image
    
$img        "DSC00".$_GET['id'].".jpg";//create filename

    
echo "<img src=\"".$img."\"/><br/><a href=\"file.php?id="
            
.$previous
            
.">Previous</a> | <a href=\"file.php?id=\""
            
.$next
            
.">Next</a>";//output the xhtml 
} else {  //if the id is 227 or id isn't set
    
$img "DSC00227.jpg";//create the filename
    
$next  228;  //make the idfor the next image
    
    
echo "<img src=\"".$img."\"/><br/><a href=\"file.php?id="
            
.$next
            
."\">Next</a>"//output the xhtml with no previous link

?>

Last edited by cdwhalley.com; 04-25-2006 at 06:06 PM..
cdwhalley.com is offline
Reply With Quote
View Public Profile Visit cdwhalley.com's homepage!
 
Old 04-25-2006, 06:39 PM Re: This should be easy
Ultra Talker

Posts: 264
Location: UK
Trades: 3
I personally suggest that you create a mysql database then you can upload the files and add a record to a database at the same time.

You can then manage the files more efficently and display images in a variety of ways, by size, style or any other defined variable.

PM me if you want me to help you more.
__________________
UKTV Index

Please login or register to view this content. Registration is FREE

Comprehensive resource for UK Television
uktvindex is offline
Reply With Quote
View Public Profile
 
Old 04-26-2006, 04:58 AM Re: This should be easy
Super Talker

Posts: 102
Trades: 0
Quote:
Originally Posted by cdwhalley.com
Save this as file.php, in the same place as all the images.
I've corrected mrpaul's code, and made it into xhtml, because (no offence) it was full of errors.
PHP Code:
<?php
if (isset($_GET['id']) && $_GET['id'] > 227){  //if the id is set and its not 227
    
$previous $_GET['id'] - 1;//make the id for the previous image
    
$next       $_GET['id'] + 1;//make the id for the next image
    
$img        "DSC00".$_GET['id'].".jpg";//create filename

    
echo "<img src=\"".$img."\"/><br/><a href=\"file.php?id="
            
.$previous
            
.">Previous</a> | <a href=\"file.php?id=\""
            
.$next
            
.">Next</a>";//output the xhtml 
} else {  //if the id is 227 or id isn't set
    
$img "DSC00227.jpg";//create the filename
    
$next  228;  //make the idfor the next image
    
    
echo "<img src=\"".$img."\"/><br/><a href=\"file.php?id="
            
.$next
            
."\">Next</a>"//output the xhtml with no previous link

?>
Thanks for your help, but when I click the next link on the first page (227) then it indeed jumps to the next (228) but at that page the previous link is kinda broken.
It's displayed like this <a href="file.php?id=227>Previous | Next

Any thoughts on how to fix this ?
ghettobert is offline
Reply With Quote
View Public Profile
 
Old 04-26-2006, 05:44 PM Re: This should be easy
cdwhalley.com's Avatar
Skilled Talker

Posts: 75
Trades: 0
Missed a "

PHP Code:
 <?php
if (isset($_GET['id']) && $_GET['id'] > 227){  //if the id is set and its not 227
    
$previous $_GET['id'] - 1;//make the id for the previous image
    
$next       $_GET['id'] + 1;//make the id for the next image
    
$img        "DSC00".$_GET['id'].".jpg";//create filename

    
echo "<img src=\"".$img."\"/><br/><a href=\"file.php?id="
            
.$previous
            
."\">Previous</a> | <a href=\"file.php?id=\""
            
.$next
            
.">Next</a>";//output the xhtml 
} else {  //if the id is 227 or id isn't set
    
$img "DSC00227.jpg";//create the filename
    
$next  228;  //make the idfor the next image
    
    
echo "<img src=\"".$img."\"/><br/><a href=\"file.php?id="
            
.$next
            
."\">Next</a>"//output the xhtml with no previous link

?>
cdwhalley.com is offline
Reply With Quote
View Public Profile Visit cdwhalley.com's homepage!
 
Old 04-27-2006, 05:39 AM Re: This should be easy
Super Talker

Posts: 102
Trades: 0
well that link is fixed now

Another problem when I'm on 228 and I click next, it goes back to 227 instead of going forward to 229. Any idea
ghettobert is offline
Reply With Quote
View Public Profile
 
Old 04-27-2006, 01:42 PM Re: This should be easy
cdwhalley.com's Avatar
Skilled Talker

Posts: 75
Trades: 0
Oh dear.
I corrected code full of mistakes, but mine has errant "s...

PHP Code:
 <?php 
if (isset($_GET['id']) && $_GET['id'] > 227){  //if the id is set and its not 227 
    
$previous $_GET['id'] - 1;//make the id for the previous image 
    
$next       $_GET['id'] + 1;//make the id for the next image 
    
$img        "DSC00".$_GET['id'].".jpg";//create filename 

    
echo "<img src=\"".$img."\"/><br/><a href=\"file.php?id=" 
            
.$previous 
            
."\">Previous</a> | <a href=\"file.php?id=" 
            
.$next 
            
."\">Next</a>";//output the xhtml  
} else {  //if the id is 227 or id isn't set 
    
$img "DSC00227.jpg";//create the filename 
    
$next  228;  //make the idfor the next image 
     
    
echo "<img src=\"".$img."\"/><br/><a href=\"file.php?id=" 
            
.$next 
            
."\">Next</a>"//output the xhtml with no previous link 
}  
?>
cdwhalley.com is offline
Reply With Quote
View Public Profile Visit cdwhalley.com's homepage!
 
Old 04-27-2006, 05:21 PM Re: This should be easy
Super Talker

Posts: 102
Trades: 0
That's great man it works now Thanks a million !!

If it's not too much to ask, could you build in a spot where I can enter in a value which is the last picture, so that it puts only the << previous link in that particular case. Just like it already has only the Next >> for the first page now, that would be really awesome
ghettobert is offline
Reply With Quote
View Public Profile
 
Old 04-27-2006, 05:43 PM Re: This should be easy
cdwhalley.com's Avatar
Skilled Talker

Posts: 75
Trades: 0
PHP Code:
<?php 
$first_number 
227;
$last_number 240;

if (!isset(
$_GET['id']) {
    
$input_number 227;
} else {
    
$input_number $_GET['id'];
}

if (
$input_number $first_number && $input_number $last_number){  
    
$previous $_GET['id'] - 1;//make the id for the previous image 
    
$next       $_GET['id'] + 1;//make the id for the next image 
    
$img        "DSC00".$_GET['id'].".jpg";//create filename 

    
echo "<img src=\"".$img."\"/><br/><a href=\"file.php?id=" 
            
.$previous 
            
."\">Previous</a> | <a href=\"file.php?id=" 
            
.$next 
            
."\">Next</a>";//output the xhtml  
} elseif ($input_number == $first_number) {
    
$img "DSC00" $input_number ".jpg";//create the filename 
    
$next  $first_number 1;  //make the idfor the next image 
     
    
echo "<img src=\"".$img."\"/><br/><a href=\"file.php?id=" 
            
.$next 
            
."\">Next</a>"//output the xhtml with no previous link 
} elseif ($input_number == $last_number) {
    
$img "DSC00" $input_number ".jpg";//create the filename 
    
$previous $last_number 1;  //make the idfor the next image 
     
    
echo "<img src=\"".$img."\"/><br/><a href=\"file.php?id=" 
            
.$previous
            
."\">Previous</a>";
}
?>
cdwhalley.com is offline
Reply With Quote
View Public Profile Visit cdwhalley.com's homepage!
 
Old 04-27-2006, 06:59 PM Re: This should be easy
Super Talker

Posts: 102
Trades: 0
Parse error: parse error, unexpected '{' in file.php on line 36

Line 36, that would be
PHP Code:
<?php  
$first_number 
227
$last_number 240

if (!isset(
$_GET['id']) {                                       << line 36
    $input_number 
227
} else { 
    
$input_number $_GET['id']; 
}

Last edited by ghettobert; 04-27-2006 at 07:03 PM..
ghettobert is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to This should be easy
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.01712 seconds with 12 queries