Jump to content

Recommended Posts

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

}

?>

Link to comment
https://forums.phpfreaks.com/topic/270496-very-newbie-requires-help/
Share on other sites

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.

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.

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>

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

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.

 

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>';

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.