phpretard Posted August 19, 2008 Share Posted August 19, 2008 It's the same except that it grows one number up to ten. But it must start at 1. if ($img1==''){$img1="Image 1 <input type=file name='img1' id='img1' disabled><input type=hidden name=blank1 value='replace'>";} else{ $img1=" <a target=_blank href='$img1'>View Image 1</a> | <a href='?page=secure/home&Spage=newProject&edit=$id&img=img1&rep=1&l=$img1'>Replace Image 1</a> <input type=hidden name=blank1 value='$img1'> "; } if ($img2==''){$img2="Image 2 <input type=file name='img2' id=img2 disabled><input type=hidden name=blank2 value='replace'>";} else{ $img2=" <a target=_blank href='$img2'>View Image 2</a> | <a href='?page=secure/home&Spage=newProject&edit=$id&img=img2&rep=1&l=$img2'>Replace Image 2</a> <input type=hidden name=blank2 value='$img2'> "; } if ($img3==''){$img3="Image 3 <input type=file name='img3' id=img3><input type=hidden name=blank3 value='replace'>";} else{ $img3=" <a target=_blank href='$img3'>View Image 3</a> | <a href='?page=secure/home&Spage=newProject&edit=$id&img=img3&rep=1&l=$img3'>Replace Image 1</a> <input type=hidden name=blank3 value='$img3'> "; } if ($img4==''){$img4="Image 4 <input type=file name='img4'><input type=hidden name=blank4 value='replace'>";} else{ $img4=" <a target=_blank href='$img4'>View Image 4</a> | <a href='?page=secure/home&Spage=newProject&edit=$id&img=img1&rep=1&l=$img4'>Replace Image 4</a> <input type=hidden name=blank4 value='$img4'> "; } if ($img5==''){$img5="Image 5 <input type=file name='img5'><input type=hidden name=blank5 value='replace'>";} else{ $img5=" <a target=_blank href='$img5'>View Image 5</a> | <a href='?page=secure/home&Spage=newProject&edit=$id&img=img5&rep=1&l=$img1'>Replace Image 5</a> <input type=hidden name=blank5 value='$img5'> "; } if ($img6==''){$img6="Image 6 <input type=file name='img6'><input type=hidden name=blank6 value='replace'>";} else{ $img6=" <a target=_blank href='$img6'>View Image 6</a> | <a href='?page=secure/home&Spage=newProject&edit=$id&img=img6&rep=1&l=$img6'>Replace Image 6</a> <input type=hidden name=blank6 value='$img6'> "; } if ($img7==''){$img7="Image 7 <input type=file name='img7'><input type=hidden name=blank7 value='replace'>";} else{ $img7=" <a target=_blank href='$img7'>View Image 7</a> | <a href='?page=secure/home&Spage=newProject&edit=$id&img=img7&rep=1&l=$img7'>Replace Image 7</a> <input type=hidden name=blank7 value='$img7'> "; } if ($img8==''){$img8="Image 8 <input type=file name='img8'><input type=hidden name=blank8 value='replace'>";} else{ $img8=" <a target=_blank href='$img8'>View Image 8</a> | <a href='?page=secure/home&Spage=newProject&edit=$id&img=img8&rep=1&l=$img8'>Replace Image 8</a> <input type=hidden name=blank8 value='$img8'> "; } You should get a good laugh from this. if ($img9==''){$img9="Image 9 <input type=file name='img9'><input type=hidden name=blank9 value='replace'>";} else{ $img9=" <a target=_blank href='$img9'>View Image 9</a> | <a href='?page=secure/home&Spage=newProject&edit=$id&img=img9&rep=1&l=$img9'>Replace Image 9</a> <input type=hidden name=blank9 value='$img9'> "; } if ($img10==''){$img10="Image 10 <input type=file name='img10'><input type=hidden name=blank10 value='replace'>";} else{ $img10=" <a target=_blank href='$img10'>View Image 10</a> | <a href='?page=secure/home&Spage=newProject&edit=$id&img=img1&rep=1&l=$img10'>Replace Image 10</a> <input type=hidden name=blank10 value='$img10'> "; } Link to comment https://forums.phpfreaks.com/topic/120336-solved-please-help-shorten-this-code/ Share on other sites More sharing options...
MasterACE14 Posted August 19, 2008 Share Posted August 19, 2008 use a while loop? Link to comment https://forums.phpfreaks.com/topic/120336-solved-please-help-shorten-this-code/#findComment-619976 Share on other sites More sharing options...
phpretard Posted August 19, 2008 Author Share Posted August 19, 2008 While what?... Link to comment https://forums.phpfreaks.com/topic/120336-solved-please-help-shorten-this-code/#findComment-619980 Share on other sites More sharing options...
MasterACE14 Posted August 19, 2008 Share Posted August 19, 2008 http://au.php.net/manual/en/control-structures.while.php Link to comment https://forums.phpfreaks.com/topic/120336-solved-please-help-shorten-this-code/#findComment-619981 Share on other sites More sharing options...
phpretard Posted August 19, 2008 Author Share Posted August 19, 2008 I have read that but I am haveing a rough time appling it here. Link to comment https://forums.phpfreaks.com/topic/120336-solved-please-help-shorten-this-code/#findComment-619988 Share on other sites More sharing options...
matmunn14 Posted August 19, 2008 Share Posted August 19, 2008 Maybe variable variables? http://au2.php.net/manual/en/language.variables.variable.php Link to comment https://forums.phpfreaks.com/topic/120336-solved-please-help-shorten-this-code/#findComment-619993 Share on other sites More sharing options...
JonnoTheDev Posted August 19, 2008 Share Posted August 19, 2008 Expand on something like the following: <?php $images = array(1,2,3,4,5); foreach($images as $imageNum) { print "Image ".$imageNum." <input type=file name='img".$imageNum."' id='img".$imageNum."' disabled><input type=hidden name=blank".$imageNum." value='replace'><br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/120336-solved-please-help-shorten-this-code/#findComment-620000 Share on other sites More sharing options...
phpretard Posted August 19, 2008 Author Share Posted August 19, 2008 Thank you! Link to comment https://forums.phpfreaks.com/topic/120336-solved-please-help-shorten-this-code/#findComment-620002 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.