daleGT Posted November 9, 2012 Share Posted November 9, 2012 Hi Guys & Girls, I've just started attempting to use PHP within Joomla to load data from an SQL database, I started off having some success but having some trouble with images. When the image is uploaded its saved on the server & the image name is saved into the database. I find when i pull the name from the database it wont re-size echo "<img src=\"http://www.blah.net/registry/partsforsale/".$row['input_image1'] ."\" height=\"$height\" width=\"$width\" />"; if i use the direct path to the image the re-size works echo "<img src=\"http://www.blah.net/registry/partsforsale/blah.jpg"\" height=\"$height\" width=\"$width\" />"; here is my code so far, no doubt most people on here could do it better, but it's doing what I want so far. any help & direction would be greatly appreciated. *btw i also need the re-sized image to link to the full size image!, but I'm working one problem at a time. <?php DEFINE ('DB_USER', 'blah'); DEFINE ('DB_PSWD', 'blah'); DEFINE ('DB_HOST', 'blah'); DEFINE ('DB_NAME', 'blah'); $dbcon = mysqli_connect(DB_HOST, DB_USER, DB_PSWD, DB_NAME); if (!$dbcon) { die('error connecting to database'); $sqlget = "SELECT * FROM Parts_For_Sale ORDER BY cf_id ASC"; $sqldata = mysqli_query($dbcon, $sqlget) or die('error getting'); } echo ''; $sqlget = "SELECT * FROM Parts_For_Sale ORDER BY cf_id ASC"; $sqldata = mysqli_query($dbcon, $sqlget) or die('error getting'); while($row = mysqli_fetch_array($sqldata, MYSQLI_ASSOC)) { Echo "<b>Part Details:</b> ".$row['input_part'] . " <br>"; Echo "<b>Price:</b> ".$row['input_price'] . " <br>"; Echo "<b>Phone:</b> ".$row['input_phone'] . " <br>"; Echo "<b>Email:</b> ".$row['input_email'] . " <br>"; $image = "http://www.blah.net/registry/partsforsale/".$row['input_image1'] ."<br>"; $size = getimagesize("$image"); $height = $size[1]; $width = $size[0]; if ($height > 150) { $height = 150; $percent = ($size[1] / $height); $width = ($size[0] / $percent); } else if ($width > 150) { $width = 150; $percent = ($size[0] / $width); $height = ($size[1] / $percent); } echo "<img src=\"http://www.blah.net/registry/partsforsale/".$row['input_image1'] ."\" height=\"$height\" width=\"$width\" />"; Echo " ".$row[''] . " <br><br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/270496-very-newbie-requires-help/ Share on other sites More sharing options...
Andy123 Posted November 9, 2012 Share Posted November 9, 2012 If I understand correctly, if you hard code the image name, everything works, but if you try to use the one from the database, it doesn't work? Did you try to check the HTML markup that is generated and see if it is the same? Your browser doesn't care or know if it's generated dynamically or hard coded. Quote Link to comment https://forums.phpfreaks.com/topic/270496-very-newbie-requires-help/#findComment-1391267 Share on other sites More sharing options...
daleGT Posted November 9, 2012 Author Share Posted November 9, 2012 Both ways show the image. From the database it doesn't re-size it. Direct does re-size. Thanks for the quick reply. Quote Link to comment https://forums.phpfreaks.com/topic/270496-very-newbie-requires-help/#findComment-1391270 Share on other sites More sharing options...
trq Posted November 9, 2012 Share Posted November 9, 2012 Neither methods are resizing the image. All they are doing is adjusting the display width and height via html. What does the end html look like in both cases? Quote Link to comment https://forums.phpfreaks.com/topic/270496-very-newbie-requires-help/#findComment-1391274 Share on other sites More sharing options...
Andy123 Posted November 9, 2012 Share Posted November 9, 2012 Obviously the HTML that is generated is not the same in both cases; otherwise, your browser would do the same thing. Please post the the HTML. And as trq says, the height and width attributes do not actually resize the image, but I don't think that is what you want to accomplish anyways. I just noticed that you are using getimagesize() incorrectly because you are including a HTML break line in the $image variable that you give to the function. I don't know why you have a break line there because you are not outputting this variable anywhere. You could do like this instead: list($width, $height, $image_type, $attributes) = getimagesize($row['input_image1']); Then you can just use $width and $height. Depending on where your image is located, you may have to build a path for getimagesize()'s parameter. Quote Link to comment https://forums.phpfreaks.com/topic/270496-very-newbie-requires-help/#findComment-1391279 Share on other sites More sharing options...
daleGT Posted November 9, 2012 Author Share Posted November 9, 2012 here is the html.....the difference is clear. height/width not showing up //name from db <b>Part Details:</b> test <br> <b>Price:</b> 1234 <br> <b>Phone:</b> 123456789 <br> <b>Email:</b> dale@dcsi.net.au <br> <img src="http://www.blah.net/registry/partsforsale/20121106204104_xb3-5.jpg" height="" width="" /> <br><br> <b>Part Details:</b> ANOTHER TEST <br> <b>Price:</b> 10 <br> <b>Phone:</b> 123456789 <br> <b>Email:</b> dale@dcsi.net.au <br> <img src="http://www.blah.net/registry/partsforsale/20121108055459_67983x944y724.jpg" height="" width="" /> <br><br> //direct <b>Part Details:</b> test <br> <b>Price:</b> 1234 <br> <b>Phone:</b> 123456789 <br> <b>Email:</b> dale@dcsi.net.au <br> <img src="http://www.blah.net/registry/partsforsale/20121106204104_xb3-5.jpg" height="150" width="226.218097448" /> <br> <b>Part Details:</b> ANOTHER TEST <br> <b>Price:</b> 10 <br> <b>Phone:</b> 123456789 <br> <b>Email:</b> dale@dcsi.net.au <br> <img src="http://www.blah.net/registry/partsforsale/20121106204104_xb3-5.jpg" height="150" width="226.218097448" /> <br> Quote Link to comment https://forums.phpfreaks.com/topic/270496-very-newbie-requires-help/#findComment-1391375 Share on other sites More sharing options...
cyberRobot Posted November 9, 2012 Share Posted November 9, 2012 The problem is probably a result of the <br> tag being added to the image name: $image = "http://www.blah.net/...sforsale/".$row['input_image1'] ."<br>"; Quote Link to comment https://forums.phpfreaks.com/topic/270496-very-newbie-requires-help/#findComment-1391379 Share on other sites More sharing options...
daleGT Posted November 10, 2012 Author Share Posted November 10, 2012 Excellent got it working, thanks for the help all who posted. I'm also looking to make the re-sized/adjusted displayed image link to the full sized image when clicked advice/tips would be great. Quote Link to comment https://forums.phpfreaks.com/topic/270496-very-newbie-requires-help/#findComment-1391478 Share on other sites More sharing options...
daleGT Posted November 10, 2012 Author Share Posted November 10, 2012 Just used *below* & it seemed to work, thought it would be harder. Echo "<a href=\"http://www.blah.net/registry/partsforsale/".$row['input_image1'] ."\"> <img src=\"http://www.blah.net/registry/partsforsale/".$row['input_image1'] ."\" height=\"$height\" width=\"$width" border=0 alt=\"" . $row['input_image1'] . "\"> </a>" ; Quote Link to comment https://forums.phpfreaks.com/topic/270496-very-newbie-requires-help/#findComment-1391484 Share on other sites More sharing options...
Andy123 Posted November 10, 2012 Share Posted November 10, 2012 I'm also looking to make the re-sized/adjusted displayed image link to the full sized image when clickedadvice/tips would be great. Try this: echo '<a href="http://www.blah.net/registry/partsforsale/' . $row['input_image1'] . '" title="View in full size">'; echo '<img src="http://www.blah.net/registry/partsforsale/' . $row['input_image1'] . '" height="' . $height. '" width="' . $width . '" />'; echo '</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/270496-very-newbie-requires-help/#findComment-1391487 Share on other sites More sharing options...
MDCode Posted November 10, 2012 Share Posted November 10, 2012 That isn't resizing an image. Quote Link to comment https://forums.phpfreaks.com/topic/270496-very-newbie-requires-help/#findComment-1391514 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.