Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable Problem. I think.

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I don't know too much about PHP, but I CAN do a few things after staring at code for hours. I have a problem I don't even know if I can explain it right.

I think it has to do with passing variables. OKay here we go:

I have a main page and an 'Image Viewer' page. So when I want to link to a picture I simply wrtie this:
Code:
<a href=&quot;images/index.php?image=imagename.jpg&quot;>
where on the image page I simply have:

Code:
<image src=<? print $image; ?> border=0>

It works just fine...

But NOW I want to have a little description of each image at the bottom of each picture with out writing something like this:

Code:
<a href=images/index.php?image=imagename.jpg?desc=A picture of my house>

which I couldn;t get to work anyway when I tried it.

So Iput a little script at the top of the image/index.php page that looks like this:

Code:
<?php
//--- default desc
$desc=&quot;No description available&quot;;

//--- read image data
$buffer=file(&quot;description.txt&quot;);

//--- convert to array
$data= array();
foreach ( $buffer as $line ){
	$data[]=explode(&quot;;&quot;,$line);
}

$found=false;
$i=0;
while( $i<count($data) and !$found ){
	if ( $id== $data[$i][0] ){
		$desc=$data[$i][1];
		$found=true;
	}
	$i++;
}
?>

the description.txt is just a simple flat textfile that reads

Code:
1;description of image goes here

So it pulls the descritpion from the txt file.

OKay it works with
Code:
<a href=&quot;images/index.php?image=imagename.jpg&quot;>
and
Code:
<a href=&quot;images/index.php?id=1&quot;>

But it won't work with both like:
Code:
<a href=&quot;images/index.php?image=imagename.jpg?id=1&quot;>

Did I explain it okay? Does anyone know what I should do? Feel free to email me if you want more info.
 
With passing values, you need a ? after the page, like:
index.php?id=1
but you need to include &'s for additional ones:
index.php?id=notld&desc=poster&type=horror 'Does my thumb look big in this?'
homebut.gif
elshtroll
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top