Jump to content

Creating Dynamic Hyperlinks


dmmichels

Recommended Posts

Hello everyone, I am new to html/javascript/php so please be patient. I am trying to put together a code that will automatically create a list of hyperlinks based on what is currently in the folder. As I add or delete items from this folder I want the code to update the list of hyperlinks. I have used some of the suggestions and code from the following thread: thread . Here is the code I am currently using:

<?php		echo '<link>';		$files = glob('*.pdf');		foreach($files as $file){			echo '<option>'.$file.'</option>';		}		echo '</link>';	?>

The result when I use this code is it will list the contents of the folder exactly by filename which is good but it is not hyperlinked. Another issue I found is that when I have two or more files in the folder they are listed one after another similar to this: filename1filename2filename3 etc. I would like them to be listed vertically not horizontal. Is what I am looking for possible or am I going about this all wrong? Any help is greatly appreciated since I am very new to this and am still learning. Thank you!-David

Link to comment
Share on other sites

In HTML, you define texted hyperlinks with the "a" element, not the "link" element. The "link" element creates links for the browser and other user agents, but not for the user. Either way ("link" or "a"), you define the location the link links to with the "href" attribute.You define lists with the "ul" or "ol" element (unordered list or ordered list). Either way, an item that is part of the list is defined with the "li" element (list item).The "option" element is intended to be an option in a dropdown menu, not in a list.With all of the above in mind, here's what you need:

<?php		echo '<ul>';		$files = glob('*.pdf');		foreach($files as $file){			echo '<li><a href="' . $file . '">' . $file . '</a></li>';		}		echo '</ul>';	?>

Link to comment
Share on other sites

In HTML, you define texted hyperlinks with the "a" element, not the "link" element. The "link" element creates links for the browser and other user agents, but not for the user. Either way ("link" or "a"), you define the location the link links to with the "href" attribute.You define lists with the "ul" or "ol" element (unordered list or ordered list). Either way, an item that is part of the list is defined with the "li" element (list item).The "option" element is intended to be an option in a dropdown menu, not in a list.With all of the above in mind, here's what you need:
<?php		echo '<ul>';		$files = glob('*.pdf');		foreach($files as $file){			echo '<li><a href="' . $file . '">' . $file . '</a></li>';		}		echo '</ul>';	?>

boen_robot, Thank you very much for your help and quick response! This code has produced the result I am looking for. Once again, much appreciated. -David
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...