Just started on PHP, need help :S

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
Makkie
Forum Newbie
Posts: 7
Joined: Mon Feb 17, 2003 4:00 pm
Location: Almere, the Netherlands

Just started on PHP, need help :S

Post by Makkie »

Hello people,

I'm just new hear.
I bought a book on PHP, read through the most part allready, and wanted to make a script to make a photo "slide show".

This is my code:
<?php
for ($pic= 1; $pic<23; $pic++)
{
('<a href="http://www.apollorecordingstudio.com/ki ... brrr/.$pic. .html" target=_down><img src="http://www.apollorecordingstudio.com/next.gif"></a>');
}
?>


I want the code to show a little button(next.gif) which refers to *$pic*.hmtl.
$pic should add 1 everytime one clicks the button

It is probably all wrong, but can someone tell me what to change, and why?
thanks in advance for your help!

greetz,
Makkie
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Try the following:

Code: Select all

<?php
for ($pic= 1; $pic<23; $pic++)
&#123;
echo "<a href="http://www.apollorecordingstudio.com/kids/pics/brrr/".$pic.".html" target=_down><img src="http://www.apollorecordingstudio.com/next.gif"></a>'";
&#125;
?>
This presumes that you've named you are loading files names "1.html" to "22.html" into a frame called "_down".

Is this what you were looking for?
Makkie
Forum Newbie
Posts: 7
Joined: Mon Feb 17, 2003 4:00 pm
Location: Almere, the Netherlands

error

Post by Makkie »

Thanks for your help.
i'm getting an error:

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /usr/local/psa/home/vhosts/apollorecordingstudio.com/httpdocs/next.php on line 6

i can't find the error in the code.. can you?
Makkie
Forum Newbie
Posts: 7
Joined: Mon Feb 17, 2003 4:00 pm
Location: Almere, the Netherlands

Post by Makkie »

if i replace the " surrounding the link and the image source by a ' i get a whole row of next buttons(22 of em, as many as the $pic var) and they link to http://www.apollorecordingstudio.com/ki ... pic.".html
this isn't exactly what i want to do with the script ;)
Makkie
Forum Newbie
Posts: 7
Joined: Mon Feb 17, 2003 4:00 pm
Location: Almere, the Netherlands

Post by Makkie »

still trying,

i edited the code like this

Code: Select all

<?php 
for ($pic= 1; $pic<23; $pic++) 
&#123; 
echo '<a href="http://www.apollorecordingstudio.com/kids/pics/brrr/' . $pic . '.html"\ target=_down><img 

src="http://www.apollorecordingstudio.com/next.gif"></a>'; 
&#125; 
?>
and now i still get the 22 next buttons, but they do link to the right file.
Now i need to make the $pic var add a number when clicked on the next button...
any ideas?
Makkie
Forum Newbie
Posts: 7
Joined: Mon Feb 17, 2003 4:00 pm
Location: Almere, the Netherlands

Post by Makkie »

i now replaced the next button by another .$pic. so i have a list in the upper frame wich counts from 1 to 23 so i can click the numbers now.
But i still prefer to click a next button or link, so i can watch the photo's one by one just clicking next....
is that possible anyway?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

yes, e.g. by passing the picture-number to the script.

Code: Select all

<?php
if (!isset($_GET['pic']))
	$pic = 1;
else
	$pic = max((int)$_GET['pic'], 0)+1;
?>
<html><head><title>picture #<?php echo $pic; ?></title></head>
<body>
	<a href="<?php echo $_SERVER['PHP_SELF'], '?pic=', $pic;?>" >next</a>
	<img src="/path/to/images/<?php echo $pic; ?>.ext" />
	<a href="<?php echo $_SERVER['PHP_SELF'], '?pic=', $pic;?>" >next</a>
</body>
</html>
(script not even tested by compiler)

this will increment the number passed via pic by one, show the according image and use the incremented number as new parameter for the link (so you can step through one by one).
You have to change the image-pat and the extension (might be .gif or .jpg or ...).
The script should also check wether there is a next image.

do not worry about the max((int)$_GET['pic'], 0), it's only to assure that the paramter pic is a number and not negative.
Makkie
Forum Newbie
Posts: 7
Joined: Mon Feb 17, 2003 4:00 pm
Location: Almere, the Netherlands

Post by Makkie »

thanks! wil try tonight, i can´t upload anything here, i´m at work right now and they are blocking uploading("%&#&#%&_).
I´ll let you know if i got it to work.
thanks again!
Makkie
Forum Newbie
Posts: 7
Joined: Mon Feb 17, 2003 4:00 pm
Location: Almere, the Netherlands

Post by Makkie »

Works great!

I changed the code a bit so i can now show next and previous picture.
Had to puzzle a bit, but it works magnificent right now!
thanks for the support
seeya guys
Post Reply