hi, i want to give a value to a variable when the surfer clicks on a link, i am not sure how to do that in php, also, i would like to pass on the value of that variable to a different page. can someone help me with the coding? plz? providing samples would be greately appreciated

Recommended Answers

All 4 Replies

When the user clicks on the link they are doing it on the "client" so you need something like javascript.

To save the value you can use sessions or cookies.

Rather than us giving you examples, maybe you'd like to tell us what the problem is that you're trying to solve!

well you see, i have links to different images. the images are categorized in folders of 20. so everytime when a user clicks on a link, i would like the variable $folder to be set to the folder name where that kind of images exist. the $folder will then be passed onto another php page where it will load all 20 images from the folder. so overall the second php page never changes, and so i don't have to creat a different page for every folder....

oh, ok

You can set your links up to be

<a href='display.php?folder=imgs1'>Images 1</a>

and then in display.php

<?php
$folder = (isset($_GET['folder']))?$_GET['folder']:'';
//echo getcwd();
//$folder = "../../../Apache Group/Apache/htdocs/gallery/images/";
$dh  = opendir($folder);
while (false !== ($filename = readdir($dh))) {
	$extbits = explode('.', strrev($filename));
	if (in_array( strtolower( strrev($extbits[0])), array('jpg','gif','png')))
	{
		$files[] = $filename;
	}
}

sort($files);

print_r($files);
?>

XD thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.