timbo8 Posted April 6, 2007 Share Posted April 6, 2007 Hi, my name is Tim and I am just starting to learn PHP. But I need some help. I want, when a user goes to the page /images.php?id=*, the script will open up an external text file, and save the text at line (id) to the variable $image. It will then open up another external .txt file, and save the text at line (id) to the variable $title. I realise that this may be hard, but please help me. Thanks in advance, Tim Quote Link to comment https://forums.phpfreaks.com/topic/45875-solved-php-help/ Share on other sites More sharing options...
jitesh Posted April 6, 2007 Share Posted April 6, 2007 Downlaod PHP manual in chm format. http://in.php.net/get/php_manual_en.chm/from/a/mirror Now refer functions fopen,fread,fwrite,fputs,fgets,file() ............. from manual. Quote Link to comment https://forums.phpfreaks.com/topic/45875-solved-php-help/#findComment-222843 Share on other sites More sharing options...
wildteen88 Posted April 6, 2007 Share Posted April 6, 2007 Could you provide more detail. I am not quite understanding what you mean by 'and save the text at line (id) to the variable $image Where is (id)? how would (id) match a line in the external text file. Quote Link to comment https://forums.phpfreaks.com/topic/45875-solved-php-help/#findComment-222844 Share on other sites More sharing options...
timbo8 Posted April 6, 2007 Author Share Posted April 6, 2007 id is a number, so it would be images.php?id=1, then 2 for the next page etc (id) is the value of ?id= Quote Link to comment https://forums.phpfreaks.com/topic/45875-solved-php-help/#findComment-222860 Share on other sites More sharing options...
maxic0 Posted April 6, 2007 Share Posted April 6, 2007 Look at a pagination tutorial, i think thats what your looking for, they have some good ones on this site. Quote Link to comment https://forums.phpfreaks.com/topic/45875-solved-php-help/#findComment-222870 Share on other sites More sharing options...
AndyB Posted April 6, 2007 Share Posted April 6, 2007 Tim - you need to explain what you are trying to do in far more detail than we have at present. I want, when a user goes to the page /images.php?id=*, the script will open up an external text file, and save the text at line (id) to the variable $image. What 'text' and where does it come from? What structure does this external text file have? Examples, please. The better you explain what you are trying to accomplish, the more likely it is that someone here will provide a solution - or suggest a better way of doing what you're hoping to do. Quote Link to comment https://forums.phpfreaks.com/topic/45875-solved-php-help/#findComment-222871 Share on other sites More sharing options...
timbo8 Posted April 6, 2007 Author Share Posted April 6, 2007 ok, the first text document will look like: /images/imagename.jpg /images/anotherimagename.jpg /images/logoforsite.gif it will list down image locations. the second text document will look like: Title for Image1 Title for Image2 Title for Image3 it will list the name of each image. So, when they go to /images.php?id=3 it can display the image located at line 3, and display the title located at line 3 Quote Link to comment https://forums.phpfreaks.com/topic/45875-solved-php-help/#findComment-223199 Share on other sites More sharing options...
wildteen88 Posted April 7, 2007 Share Posted April 7, 2007 So the id corresponds to a line in the text files? correct? try this simple bit of code: <?php if(isset($_GET['id']) && is_numeric($_GET['id'])) { // this holds the line number for our image/title in the txt file $i = ($_GET['id'] - 1); // file grabs every line in a document in to an array // read more on file here: // http://www.php.net/file $path = file('paths.txt'); $title = file('titles.txt'); $html = '<b>' . $title[$i] . '</b><br /> <img src="' . $path[$i] . '" title="' . $title[$i] . '" />'; echo $html . '<hr />'; } ?> Choose an image to be displayed:<br /> <a href="?id=1">Get image #1</a> <a href="?id=2">Get image #2</a> <a href="?id=3">Get image #3</a> This code gets the paths of the images from a file call paths.txt and the titles for the image from titles.txt Quote Link to comment https://forums.phpfreaks.com/topic/45875-solved-php-help/#findComment-223505 Share on other sites More sharing options...
timbo8 Posted April 7, 2007 Author Share Posted April 7, 2007 Thank you wildteen88, that is exactly what I needed, and it works like a charm. Quote Link to comment https://forums.phpfreaks.com/topic/45875-solved-php-help/#findComment-223546 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.