Click to See Complete Forum and Search --> : PHP Novice need little help and advice with script


jamesonnow
08-31-2006, 09:36 PM
I got this script and a lot of things seemed to be a little mixed up and being that i dont know much on PHP i wasnt able to fix it so I figured I would put this out there and see if I could get some help from people who know what they are doing. Basically what i need the page to do is generate a table of all the images in a folder, as well as next to each image a text field, with html code on how to link to the specific image. Something like <A HREF="http://www.sitename.com/gallery/image1.jpg> </A>. Would like to set the amount of images that show up on one page and and have several pages if necessary. Have tried to figure it out and couldnt get it working, and frankly I may have messed it up further.

This is what I have (kinda incomplete), Any positive advice would be appreciated. Thank you


if($_GET['pg'])
{


$path = $sm['path_base'] . 'graphics/' . $_GET['pg'];


echo "<table width="100%" align="center">
<tr>
<td style="padding-right: 10px;"><div class="text"><div align="center">Just copy and paste the code where you would like the picture to be!<br></div>
<br>";

echo " <table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td style="padding-right: 10px;" class="too"><a href="" . $sm['url_base'] . "graphics/" . $_GET['pg'] . "/$file" target="_blank"><img src="" . $sm['url_base'] . "graphics/" . $_GET['pg'] . "/$file" width="150" height="150" border="1" style="border-color: 000000;"></a><br><div align="center"><a href="" . $sm['url_base'] . "/graphics/" . $_GET['pg'] . "/$file"></a></div></td>
<td class="too" valign="top"><div style="padding-bottom: 5px;"></div>
<textarea name="textarea" cols=23 rows=8 class="bginput" onClick="this.focus();this.select()"><a href="" . $sm['url_base'] . "" ><img src="" . $sm['url_base'] . "graphics/" . $_GET['pg'] . "/$file" border="0"></a>

</table>
<br/>
<br>";
}
echo "
</td>
</tr>
</table>";

}



Is it possible to get it working without having to call information from a database, or basically what would be the most efficient way of doing this.

Lastly can anyone recommend any good PHP books that I could read up on. Thank you

shane.carr
08-31-2006, 11:57 PM
Personally, I don't like databases, and you don't need one anyway. This code should do the trick:

$all = glob("/gallery/*");//path to the directory where the pictures are
echo "<table style=\"border:1px solid #000000;\">";
foreach($all as $num => $one){
echo "<tr><td><img src=\"".$one."\" alt=\"".$num."\" /></td><td><a href=\"".$one."\">See full-size image</td></tr>";
}
echo "</table>";

jamesonnow
09-04-2006, 02:12 PM
Thanks alot appreciate the help

Sheldon
09-04-2006, 02:19 PM
If you dont like databases its because you dont know how to use them, They are one of any developers best friends.
Dont use tables try this

<ul>
<?php



$dir = "./images/";



if (is_dir($dir)){

if ($dh = opendir($dir)) {

while (($file = readdir($dh)) !== false) {

if(eregi('.jpg$', $file)){

echo "<li><img src=\"".$dir.$file."\" alt=\"\" /><</li>"."\n";

}

}

closedir($dh);

}

}



?>
</ul>

DJsAC
09-04-2006, 03:14 PM
echo "<li><img src=\"".$dir.$file."\" alt=\"\" /><</li>"."\n";

should be
echo "<li><img src=\"".$dir.$file."\" alt=\"\" /></li>"."\n";

in sheldon's script.. ;)

shane.carr
09-04-2006, 03:31 PM
$all = glob("/gallery/*");//path to the directory where the pictures are
echo "<ol>";
foreach($all as $num => $one){
echo "<li><a href=\"".$one."\"><img src=\"".$one."\" alt=\"".$num."\" />&nbsp;&nbsp;See full-size image</li>";
}
echo "</ol>";