Page 1 of 1

noob basic php question - variables carrying over via links

Posted: Sun May 23, 2010 12:01 am
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.

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

Posted: Sun May 23, 2010 12:33 am
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.

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

Posted: Sun May 23, 2010 3:04 am
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.

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

Posted: Sun May 23, 2010 4:11 pm
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