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.  ???
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">

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
<?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>";
      }

?>
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.
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>";
      }

?>
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


Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.