Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

not displaying from MySQL

Featured Replies

Hi

I'm trying to make a gallery in php, the pictures are in MySQL database but when I View it in the browsers the pictures don't display just the alt or the red x. Can anyone help I'm new to php. Do I have to enable something on the server?

Hi

I'm trying to make a gallery in php, the pictures are in MySQL database but when I View it in the browsers the pictures don't display just the alt or the red x. Can anyone help I'm new to php. Do I have to enable something on the server?

 

how are the images stored in the database, also can you show the code in html that loads the picture.

 

Pat

Avoid using BINARY/BLOB types to store data in the database, the overheads are pretty high and shared hosting usualyl won't allow you to.

Yea, we need some more info like your request query and some html code.

Hi

I'm trying to make a gallery in php, the pictures are in MySQL database but when I View it in the browsers the pictures don't display just the alt or the red x. Can anyone help I'm new to php. Do I have to enable something on the server?

 

Best way to store images is just use a VARCHAR and store the exact path of the images atleast i find it useful this way.And to display them use a while loop to loop through each one<_<

Another fairly simple way:

 

<?php
// Define a specific format for the image.
$imageFormat	=	'<li><img src="%s" alt="%s" width="125" height="125" /></li>';

// Settings
$images		=	NULL;
$imagePath	=	'static/images/';

// Run
$files	=	glob($imagePath.'*.png');
$total	=	count($files);

// Check if it's found any.
if ($total != 0)
{
foreach($files as $file)
{
	// Path info.
	$info	=	pathinfo($file);

	// Build up image string.
	$images.=	vsprintf($imageFormat,array($imagePath.$info['basename'],$info['filename']));
}

// The result.
echo '<ul class="gallery">'.$images.'</ul>';
}
else
{
echo 'No images!';

}

  • Author

I stored the images on the database using VARCHAR.

This is the HTML code :

 

 

<h1><br />
    Tanzania Photo Gallery </h1>
	<p> </p>
	<div id="pictureWrapper">
  	<div id="mainpic"><img <?php echo getDims($row_getPictures['image'],'orginal/gallery_php/main_pics/');?> src="<?php echo $row_getPictures['../../gallary/image']; ?>" alt="<?php echo $row_getPictures['caption']; ?>" /></div>
  	<p id="picCaption"><?php echo $row_getPictures['caption']; ?></p>
	</div>
   <div id="thumbnails">
  	<table>
		<tr>
  		<?php
 do { // horizontal looper version 3
?>
    		<td><a href="orginal/gallery_php/main_pics/<?php echo $row_getPictures['image']; ?>"onclick="showImage(this);return false;"><img src="orginal/gallery_php/thumbnails/<?php echo $row_getPictures['image']; ?>" border="0" <?php echo getDims($row_getPictures['image'],'orginal/gallery_php/thumbnails/'); ?> /></a></td>
    		<?php
   $row_getPictures = mysql_fetch_assoc($getPictures);
   if (!isset($nested_getPictures)) {
     $nested_getPictures= 1;
   }
   if (isset($row_getPictures) && is_array($row_getPictures) && $nested_getPictures++ % 3==0) {
     echo "</tr><tr>";
   }
 } while ($row_getPictures); //end horizontal looper version 3
?>
		</tr>
  	</table>

  	<table id="pageNav">
		<tr>
  		<td width="23%" align="center"><?php if ($pageNum_getPictures > 0) { // Show if not first page ?>
        		<a href="<?php printf("%s?pageNum_getPictures=%d%s", $currentPage, 0, $queryString_getPictures); ?>"><img src="First.gif" border=0></a>
        		<?php } // Show if not first page ?>
  		</td>
  		<td width="31%" align="center"><?php if ($pageNum_getPictures > 0) { // Show if not first page ?>
        		<a href="<?php printf("%s?pageNum_getPictures=%d%s", $currentPage, max(0, $pageNum_getPictures - 1), $queryString_getPictures); ?>"><img src="Previous.gif" border=0></a>
        		<?php } // Show if not first page ?>
  		</td>
  		<td width="23%" align="center"><?php if ($pageNum_getPictures < $totalPages_getPictures) { // Show if not last page ?>
        		<a href="<?php printf("%s?pageNum_getPictures=%d%s", $currentPage, min($totalPages_getPictures, $pageNum_getPictures + 1), $queryString_getPictures); ?>"><img src="Next.gif" border=0></a>
        		<?php } // Show if not last page ?>
  		</td>
  		<td width="23%" align="center"><?php if ($pageNum_getPictures < $totalPages_getPictures) { // Show if not last page ?>
        		<a href="<?php printf("%s?pageNum_getPictures=%d%s", $currentPage, $totalPages_getPictures, $queryString_getPictures); ?>"><img src="Last.gif" border=0></a>
        		<?php } // Show if not last page ?>
  		</td>
		</tr>
  	</table>
  	<p><?php include('message.txt'); ?> </p>
   </div>

Edited by Sam G
added [code] tags

  • Author

I tried using BLOB and loading the images on to see if was because I was using VARCHAR but I still get no Pictures just the captions.

In the html you posted their doesnt seem to be any connection to the database, or did you just not post that bit

  • Author

Yes the ($row_getPictures ['image'], is the connection to the database, getPictures is the name of the recordset and 'orginal/gallery_php/main_pics/') is the path to the photos. I'm using dreamweaver 8 I inserted the picture and selected data source and selected the recordset and ['image'] which is the name of the column the photos are in, in the database.

 

<img <?php echo getDims($row_getPictures['image'],'orginal/gallery_php/main_pics/');?> src="<?php echo $row_getPictures['../../gallary/image']; ?>" alt="<?php echo $row_getPictures['caption']; ?>" /></div> <p id="picCaption"><?php echo $row_getPictures['caption']; ?></p>

Yes the ($row_getPictures ['image'], is the connection to the database, getPictures is the name of the recordset and 'orginal/gallery_php/main_pics/') is the path to the photos. I'm using dreamweaver 8 I inserted the picture and selected data source and selected the recordset and ['image'] which is the name of the column the photos are in, in the database.

 

<img <?php echo getDims($row_getPictures['image'],'orginal/gallery_php/main_pics/');?> src="<?php echo $row_getPictures['../../gallary/image']; ?>" alt="<?php echo $row_getPictures['caption']; ?>" /></div> <p id="picCaption"><?php echo $row_getPictures['caption']; ?></p>

 

try this..

<img <?php echo getDims($row_getPictures['image'],'orginal/gallery_php/main_pics/');?>  src="orginal/gallery_php/main_pics/<?php echo $row_getPictures['image']; ?>" alt="<?php echo $row_getPictures['caption']; ?>" /></div>  <p id="picCaption"><?php echo $row_getPictures['caption']; ?></p>

 

 

as if $row_getPictures['image']; pull through the name of the file (i.e. myfile.jpg) you just need to prepend it onto the path.

 

original/gallery_php/main_pics/<?php echo $row_getPictures['image']; ?>

 

.. But of course thats me doing it blindly.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.