free_man Posted October 16, 2012 Share Posted October 16, 2012 I have the following code in index.php: ... <table width="30%" border="0" cellpadding="7" cellspacing="5"><tr> <td><a href="http://localhost/image.php?view=1"><img src="/images/image(1).JPG" width=200 height=170/></a></td> <td><a href="http://localhost/image.php?view=2"><img src="/images/image(2).JPG" width=200 height=170/></a>></td> <td><a href="http://localhost/image.php?view=3"><img src="/images/image(3).JPG" width=200 height=170/></a></td> </tr> </table> ... where users chooses which image want to see in bigger size using page image.php: <?php $view1= $_GET['view']; if ($view1 == 1) { echo '<img src="/images/image(1).JPG" WIDTH=500 HEIGHT=400/>'; } elseif ($view1 == 2) { echo '<img src="/images/image(2).JPG" WIDTH=500 HEIGHT=400/>'; } else { echo '<img src="/images/image(3).JPG" WIDTH=500 HEIGHT=400/>'; } ?> but photos do not load. Can anyone figure out what's going wrong? Thanks Quote Link to comment Share on other sites More sharing options...
White_Lily Posted October 16, 2012 Share Posted October 16, 2012 Are you planning on having more than 3 images? If so I think you may want to re-think your code. Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted October 16, 2012 Share Posted October 16, 2012 Describe "photos don't load." In the first page? In the second? Does the HTML work? Black image? Broken image? Your have invalid HTML in your index page, there's a >> that shouldn't be there. Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 16, 2012 Share Posted October 16, 2012 Well, you should definitely rethink the process, but the problem is that your parameter name is "view" <td><a href="http://localhost/ima...hp?view=1"><img src="/images/image(1).JPG" width=200 height=170/></a></td> But, in your processing code you are checking "view1" if ($view1 == 1) Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted October 16, 2012 Share Posted October 16, 2012 He assigns $view1= $_GET['view'], so that's not it. Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 16, 2012 Share Posted October 16, 2012 (edited) images_list.php (a file to define all the available images and the image directory) <?php $imageDir = '/images/'; $images = array( '1' => 'image(1).JPG', '2' => 'image(2).JPG', '3' => 'image(3).JPG' ); ?> index.php (dynamically create the links based upon the defined images) <?php include(images_list.php); echo "<table width='30%' border='0' cellpadding='7' cellspacing='5'>\n"; echo "<tr>\n"; foreach($images as $imageID => $imageName) { echo "<td><a href='http://localhost/image.php?view={$imageID}'><img src='{$imageDir}{$imageName}' width='200' height='170' /></a></td>\n"; } echo "</tr>\n"; echo "</table>\n"; ?> image.php (dynamically show the image comparing to the images list) <?php include(images_list.php); $imageID = isset($_GET['view']) ? intval($_GET['view']) : false; if($imageID===false || !in_arraY($imageID, $images)) { echo "No image selected!"; } else { $imageName = $images[$imageID]; echo "<img src='{$imageDir}{$imageName}' WIDTH='500' HEIGHT='400' />n\"; } ?> Note that using full size images as previews is a based idea as it still requires the user to download the full images. You should instead create smaller versions of the full size images and use those in the previews. Using the process above you could just create a subfolder (e.g. 'thumbs') and put the smaller images in there. They should have the same name as the full-size. Then, just change the index.php page to use the subfolder when creating the previews. Edited October 16, 2012 by Psycho Quote Link to comment Share on other sites More sharing options...
free_man Posted October 16, 2012 Author Share Posted October 16, 2012 Describe "photos don't load." In the first page? In the second? Does the HTML work? Black image? Broken image? Your have invalid HTML in your index page, there's a >> that shouldn't be there. The first page (index.php) loads fine. The problem is that in second page images don't load (i don't get a broken image icon just a white page). I have tried to change ' or " symbols in case the problem is there but nothing happened. Quote Link to comment Share on other sites More sharing options...
White_Lily Posted October 16, 2012 Share Posted October 16, 2012 Try putting the width and height figures in double quotes. Quote Link to comment Share on other sites More sharing options...
White_Lily Posted October 16, 2012 Share Posted October 16, 2012 Its just a completely blank page? Check your php.ini settings if this is the case. Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted October 16, 2012 Share Posted October 16, 2012 Is there data in the source of the page? Do you have error_reporting turned on? Quote Link to comment Share on other sites More sharing options...
White_Lily Posted October 16, 2012 Share Posted October 16, 2012 your php.ini file should be this: display_errors = On error_reporting = E_ALL Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 16, 2012 Share Posted October 16, 2012 display_errors = On error_reporting = -1 is what you should be using while developing. Quote Link to comment Share on other sites More sharing options...
free_man Posted October 16, 2012 Author Share Posted October 16, 2012 (edited) I think Psycho code works fine (at image.php />n\"; must be />\n" ; but i am trying to change a page that a friend made with a tool that generated the code. Because it has many tables and tags in it i guess there should be the problem (view source code ends before i put my php code). Thanks for your answers anyway! Edited October 16, 2012 by free_man Quote Link to comment Share on other sites More sharing options...
Christian F. Posted October 16, 2012 Share Posted October 16, 2012 I'd use rawurlencode () on those filenames, if I were you. I suspect it might help. That is, if you are 100% certain that the files are correctly named, including upper-lower case differences, and stored in the images/ folder of your web root. Also, you state that "view source" ends before you put your PHP code. Should that be "put in" or "where I put"? In either case it suggests that you have a problem prior to the code you've pasted, or you're talking about something else. Showing us the results would go a long way in clearing up the confusion, and letting us know exactly what's going on. Quote Link to comment Share on other sites More sharing options...
White_Lily Posted October 17, 2012 Share Posted October 17, 2012 All we can see is broken images. Quote Link to comment Share on other sites More sharing options...
JohnTipperton Posted October 19, 2012 Share Posted October 19, 2012 (edited) i did tested your work in my localhost and it works. try my revise code test.php <table width="30%" border="0" cellpadding="7" cellspacing="5"><tr> <td><a href="test2.php?view=1"><img src="spike.jpg" width=102 height=147/></a></td> </tr> </table> test2.php <?php $view1= $_GET['view']; if ($view1 == 1) { echo '<img src="spike.jpg" WIDTH=500 HEIGHT=400/>'; } elseif ($view1 == 2) { echo '<img src="spike2.jpg" WIDTH=500 HEIGHT=400/>'; } else { echo '<img src="spike3.jpg" WIDTH=500 HEIGHT=400/>'; } ?> Edited October 19, 2012 by JohnTipperton Quote Link to comment 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.