Jump to content

dispalying images from your server folder???? Help Please


spires

Recommended Posts

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.
<?php
include('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.  ???
Link to comment
Share on other sites

an example only ok.

this is a database exmple and the image is in the database ok.

<?php
include('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">

Link to comment
Share on other sites

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?

<?php
include('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>';
}

?>

ERROR
Parse error: syntax error, unexpected '{' in D:\Domains\spirestest.com\wwwroot\login2\news\image_show.php on line 11

Thanks  ;D
Link to comment
Share on other sites

<?php
include('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>";
      }

?>
Link to comment
Share on other sites

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 11

I cant see anything wrong it at all? its saying { shouldn't be there after the while statment?

<?php
include('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.
Link to comment
Share on other sites

try that 1 moment ok

<?php
include('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>";
      }

?>
Link to comment
Share on other sites

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, 3
no need for an $img arraay. just use echo $i where $i = 1 and $i++ in ur for loop
?>

hope thats what u wanted


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.