noob basic php question - variables carrying over via links

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
Loss512
Forum Newbie
Posts: 2
Joined: Sat May 22, 2010 11:25 pm

noob basic php question - variables carrying over via links

Post by Loss512 »

What I'm trying to do is this:

gallery.php
<a href="index.php?page=gallery2" $path=path-001 $image=image>
<a href="index.php?page=gallery2" $path=path-002 $image=image>
<a href="index.php?page=gallery2" $path=path-003 $image=image>
etc..

and have those values appear here:

gallery2.php
<img src="images/$path/s-$image-1.jpg">
<img src="images/$path/s-$image-2.jpg">
<img src="images/$path/s-$image-3.jpg">
etc..

for an end result of:
<img src="images/path-001/s-image-1.jpg">
<img src="images/path-001/s-image-2.jpg">
<img src="images/path-001/s-image-3.jpg">

I intend to have a few hundred pages of these pictures with the same path and naming structure, and am trying to keep the HTML and # of pages to a bare minimum on my site. I admit I have no clue how to make the desired effect happen - i've viewed dozens of tutorials on sessions and cookies, and each and every last one I've checked shows examples of how to show users the date & time, their # of visits to your website, or to tell them what their name is after they've entered it in a text box; but not a single example of using a link to change variables for the target page :banghead: someone shares my question here: http://webforumz.com/classic-asp/67473- ... icking.htm and has not had any answers yet.

Thanks in advance for any help or useful links/references that I've missed on the subject.
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Re: noob basic php question - variables carrying over via li

Post by Chalks »

I'm not exactly sure what you're looking for, but I think you should look into $_GET variables. I'm fairly sure that will get you at least closer to your goal. $_GET: when you form a url, you can insert variables. So, http://mysite.com/index.php?page=gallery&path=path-001 means you have two variables in the $_GET array: $_GET['page'] and $_GET['path']. The values of these are "gallery" and "path-001" respectively.


If you are trying to make each page remember "hundreds of variables" that can't be created from one or two variables passed through the url, then your best bet is probably going to be to store those variables in a mysql table or possibly just include a separate php file. The former option is probably better... google mysql/php tutorials if you need it, it's pretty easy to pick up fast.
User avatar
zeus1
Forum Newbie
Posts: 22
Joined: Tue May 18, 2010 10:45 pm
Location: /Under/The/AppleTree.png

Re: noob basic php question - variables carrying over via li

Post by zeus1 »

Just reiterating what Chalks is stating. Basically you are going to use the URL to send variables.


gallery.php

Code: Select all

<a href="index.php?page=gallery2&path=001&image=We_got_foo_at_the_bar.jpg) 
gallery2.php

Code: Select all

 //construct image path
<?$path = "images/path-".$_GET["path"]."/s-".$_GET["image"].; ?>
<img src=" <? echo $path;  ?> ">
This should work.
Loss512
Forum Newbie
Posts: 2
Joined: Sat May 22, 2010 11:25 pm

Re: noob basic php question - variables carrying over via li

Post by Loss512 »

thank you for the reply. the $_get function was something I had toyed with earlier but my browser wouldn't replace the $image and $path on it's own - I didn't read clearly enough into the tutorials to know that the echo command was necessary to make it all work :oops: I put the echo string in the image path and it works perfectly now.

Thanks :D
Post Reply