Jump to content

Recommended Posts

I am trying to create a HTML table that is a max of 4 cells accross & an unspecified amount down.

 

In each of these cells there will be an image taken from a Mysql Server.

 

The code below only shows 1 cell accross, How can i get the code to put a picture in each cell?

<?php       
   
      $Sql = "SELECT * FROM `prod_listing` WHERE Product_ID = '$id'";
      $picresult = mysql_query($Sql);
?>
<table width="30%" border="0" cellpadding="1" cellspacing="0" bordercolor="#FFFFFF">
<?php while ($row=mysql_fetch_array($picresult)) { ?>

      <td height="32"><img name="" src="<?php echo $row["Product_picurl"];?>" alt=""></td>
 <?php } //end of loop ?>  
</table>

 

thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/95541-simple-php-photogallery/
Share on other sites

try something like this

<?php       
   
      $Sql = "SELECT * FROM `prod_listing` WHERE Product_ID = '$id'";
      $picresult = mysql_query($Sql);
?>
<table width="30%" border="0" cellpadding="1" cellspacing="0" bordercolor="#FFFFFF">
<?php
$t = 4;
$c = 4;
while ($row=mysql_fetch_array($picresult)) { ?>
<tr>
      <td height="32"><img name="" src="<?php echo $row["Product_picurl"];?>" alt=""></td>
<?php 
if($c == 0)
{
$c=$t;
echo "<\tr><tr>";
}
$c--;
} //end of loop ?>  
</tr>
</table>

Thanks for the help.

 

I tried to set the image size in the script andcame across a Problem:

 

Some of my images are  different sizes and just resizing it to 150 x 150 will only mess up the pictures.

 

Is there a script outthere that will rescale the picture on loading or willi have to resize all the pics manually?

 

Thanks in advance

try something like this

<?php
list($width, $height) = getimagesize($row["Product_picurl"]);
$long = ($width>$height)?"Width":"Height";
?>
<img name="" src="<?php echo $row["Product_picurl"];?>" alt="" <?php echo $long="150" ?> onclick="window.open('<?php echo $row["Product_picurl"];?>');">

it timedout!!.. are the images stored on your webhost?

also do you have the image file path, instead of the html path?

 

What is the difference between the two paths?

 

My pictures are stored on the manufacturers websites, this reduces our bandwidth but eans that the pictures come in various sizes.

 

 

 

 

 

seen this:http://www.sitepoint.com/article/image-resizing-php

 

 

<?php

function imageResize($width, $height, $target) {

//takes the larger size of the width and height and applies the  
formula accordingly...this is so this script will work  
dynamically with any size image

if ($width > $height) {
$percentage = ($target / $width);
} else {
$percentage = ($target / $height);
}

//gets the new value and applies the percentage, then rounds the value
$width = round($width * $percentage);
$height = round($height * $percentage);

//returns the new sizes in html image tag format...this is so you
can plug this function inside an image tag and just get the

return "width=\"$width\" height=\"$height\"";

}

?>

 

 

<?php

//get the image size of the picture and load it into an array
$mysock = getimagesize("images/sock001.jpg");

?>

<!-using a standard html image tag, where you would have the  
width and height, insert your new imageResize() function with  
the correct attributes -->

<img src="images/sock001.jpg" <?php imageResize($mysock[0],  
$mysock[1], 150); ?>>

 

how can i adapt it to get the image url from mysql?

 

thanks in advance

 

the problem about using unmanaged offsite images is your can not get the size of the images unless you use  getimagesize(); which timesout as it need to connect to the other sites..

i guess your need to look into a CSS solution or download the images to your site..

 

EDIT: oh that code won't work if mine timesout so will that code, they both relie on getimagesize()

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.