spires Posted July 6, 2006 Share Posted July 6, 2006 Hi , This is my first attempt at uploading image into a folder on the server, then displaying them. I have managed to upload the images 'name.jpg' to the images folder. But, i dont know how to pull the images out of the folder, other than using '<img src="images/bailey.jpg">'.Which works, but i need to be able to pull them out using some sort of unique ID. as i want to pull them out in a 'for loop',Each loop displaying a different image. Any ideas????Heres my code.<?phpinclude('db.php'); $sql = "SELECT * FROM image"; $query = mysql_query($sql) or die('Query failed: ' . mysql_error()); for ($i=0; $i < 16; $i++){ $row = mysql_fetch_array($query); echo '<table> <tr> <td> '.$row['id'].', '.$row['name'].', '.$row['description'].', <img src="images/bailey.jpg"> </td> </tr> </table>'; }?>Thanks for any help. ??? Quote Link to comment https://forums.phpfreaks.com/topic/13892-dispalying-images-from-your-server-folder-help-please/ Share on other sites More sharing options...
redarrow Posted July 6, 2006 Share Posted July 6, 2006 an example only ok.this is a database exmple and the image is in the database ok.<?phpinclude('db.php'); $sql = "SELECT * FROM image where id='$id' "; $query = mysql_query($sql) or die('Query failed: ' . mysql_error()); while($record=mysql_fetch_assocc($query) { ?> <table> <tr> <td> <img src='images/"'.$record['image'].'"'> </td> </tr> </table>"; <}?>if an image was not in a database then you can also use this method ok.<?$img="bailey.jpg";<img src="images/$img"> Quote Link to comment https://forums.phpfreaks.com/topic/13892-dispalying-images-from-your-server-folder-help-please/#findComment-54110 Share on other sites More sharing options...
redarrow Posted July 6, 2006 Share Posted July 6, 2006 sorry just use roundSELECT * FROM tbl_name ORDER BY RAND(); Quote Link to comment https://forums.phpfreaks.com/topic/13892-dispalying-images-from-your-server-folder-help-please/#findComment-54115 Share on other sites More sharing options...
spires Posted July 6, 2006 Author Share Posted July 6, 2006 Alright. Thanks for your help, But, i think i'm doing something wrong. i'm quite new to PHP (user for only 2 weeks).and am now getting an error. Any more help please?<?phpinclude('db.php'); $sql = "SELECT * FROM image ORDER BY RAND()"; $query = mysql_query($sql) or die('Query failed: ' . mysql_error()); while ($row = mysql_fetch_assoc($query) { echo '<table> <tr> <td> '.$row['id'].', '.$row['name'].', '.$row['description'].', <img src="images/"'.$row['image'].'""> </td> </tr> </table>'; }?> ERRORParse error: syntax error, unexpected '{' in D:\Domains\spirestest.com\wwwroot\login2\news\image_show.php on line 11Thanks ;D Quote Link to comment https://forums.phpfreaks.com/topic/13892-dispalying-images-from-your-server-folder-help-please/#findComment-54119 Share on other sites More sharing options...
redarrow Posted July 6, 2006 Share Posted July 6, 2006 <?phpinclude('db.php'); $sql = "SELECT * FROM image where id='$id' "; $query = mysql_query($sql) or die('Query failed: ' . mysql_error()); while ($row = mysql_fetch_assoc($query) { echo "<table> <tr> <td> "'.$row['id'].'", "'.$row['name'].'", "'.$row['description'].'", <img src="images/"'.$row['image'].'""> </td> </tr> </table>"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/13892-dispalying-images-from-your-server-folder-help-please/#findComment-54125 Share on other sites More sharing options...
spires Posted July 6, 2006 Author Share Posted July 6, 2006 Thanks for your help again.but i'm still getting this error.Parse error: syntax error, unexpected '{' in D:\Domains\spirestest.com\wwwroot\login2\news\image_show.php on line 11I cant see anything wrong it at all? its saying { shouldn't be there after the while statment?<?phpinclude('db.php'); $sql = "SELECT * FROM image where id='$id' "; $query = mysql_query($sql) or die('Query failed: ' . mysql_error()); while ($row = mysql_fetch_assoc($query) { echo "<table> <tr> <td> "'.$row['id'].'", "'.$row['name'].'", "'.$row['description'].'", <img src="images/"'.$row['image'].'""> </td> </tr> </table>"; }?> Sorry to keep bugging you. Quote Link to comment https://forums.phpfreaks.com/topic/13892-dispalying-images-from-your-server-folder-help-please/#findComment-54133 Share on other sites More sharing options...
redarrow Posted July 6, 2006 Share Posted July 6, 2006 try that 1 moment ok<?phpinclude('db.php'); $sql = "SELECT * FROM image where id='$id' "; $query = mysql_query($sql) or die('Query failed: ' . mysql_error()); while ($row = mysql_fetch_assoc($query) { echo "<table> <tr> <td> <img src='images/" ' .$row['image']. ' " '> </td> </tr> </table>"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/13892-dispalying-images-from-your-server-folder-help-please/#findComment-54135 Share on other sites More sharing options...
krone Posted July 7, 2006 Share Posted July 7, 2006 at work so syntax might be a little off :)in half psuedo (cus im lazy)<?php $path = /somepath/path$img = array{'imgName1', 'imgName2'....};for (blah... { ?><td>blah <img src = '<?php echo $img[$i]; ?>.jpg'> </td>// just echo the names of the images... if ur unique id is incremental u like.. 1, 2, 3no need for an $img arraay. just use echo $i where $i = 1 and $i++ in ur for loop?>hope thats what u wanted Quote Link to comment https://forums.phpfreaks.com/topic/13892-dispalying-images-from-your-server-folder-help-please/#findComment-54232 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.