Jump to content

Need a help with PHP Code


xuykin

Recommended Posts

Hi Guys,

 

I'm new to PHP programming and hope you can help me here. I have difficulty comprehending functions in PHP.

Here is what I am trying to accomplish:

 

I have a website that automatically pulls the content from MySQL database and puts them out. I am able to connect and retrieve the content and put them on, however the problem I am encountering is automatically resizing picture and placing javascript affiliate link underneath the picture. Since, I have more than 2000 items on the database I will like to be able to split that content into 100 pages (20 in each page). I don't know how to do that.

Here is my code I am having a trouble with:

 

<?php

// this calulates resizing

 

 

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

 

 

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

 

 

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

 

 

}

 

?>

 

 

<?php

//this creates array

 

$rcimage = getimagesize("http://images.xxxxxx.com");

 

 

?>

 

 

<img src="http://images.xxxx.com" width="125" <?php echo imageResize($rcimage[0], 

$rcimage[1], 125); ?> />

 

 

 

<?php

 

 

//Connect To Database pulls information

$hostname='xxxxxx';

$username='yyyy';

$password='zzzzz';

$dbname='aaaaa';

$usertable='bbbbbbbbbb';

 

 

mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');

mysql_select_db($dbname);

 

 

$query = 'SELECT DISTINCT `IMAGEURL`, `NAME`, `CURRENCY`, `PRICE`, `BUYURL` FROM `bbbbbbbbbb` WHERE `NAME` LIKE \'%heli%\' LIMIT 0, 20 ';

$result = mysql_query($query);

 

if($result) {

    while($row = mysql_fetch_array($result)){

    $imageurl=$row[0];

$name = $row[1];

$currency=$row[2];

$price=$row[3];

$buyurl=$row[4];

 

 

        echo "<div class=\"contenttopcenter2\" <img src=\"$imageurl\"  <?php echo imageResize($rcimage[0],$rcimage[1], 125);  /> ?> $name, $currency, $price, $buyurl

        </div>";

    }

}

 

 

 

?>

 

 

The piece of code I am having a problem is highlighted in red and orange color.

 

Link to comment
Share on other sites

Just follow up clarification: My problem with the code is that it does not resize the image. Works well if I have manual link to the image, but when php retrieves image url from the array the second echo for <img parameters does not work.

Link to comment
Share on other sites

AdRock,

 

Thank you! Looks like it solved error issues and did resize images, however all images resized and given  static value as for width and height. Is it what supposed to happen? :shrug:

 

Thank you for the reply. I have learned today how to use concatenation properly!

Link to comment
Share on other sites

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.