Blog

Newest Post
Blog Archives
Blog Categories

Portfolio

3D Models
Banners
Brochures
Business Cards
Custom Programming
Environments
Flash Projects
Game Design
Image Altering
Web Design

About

Resume
Recommendation Letters

Contact

November 12, 2009

Use PHP to proportionally scale an image

Filed under: PHP, The Coding World — admin @ 3:06 pm

I wrote the following function to proportionally scale images that I was pulling from a directory.

 
function img_size($img,$alt) {
 
  list($width,$height) = getimagesize($img);
 
  $maxwidth = 140; //set max width here
 
  if ($width > $maxwidth) {
	$i = $width - $maxwidth;
	$x = $width - $i;
	$percent = $maxwidth/$width;
  }
  else
  {
    $x = $width;
    $percent = 1;
  }
 
  $y = $percent * $height;
 
  $img_src = '<img src="'.$img.'" width="'.$x.'" height="'.$y.'" alt="'.$alt.'" border="0" />';
 
  return $img_src;
}
 
echo img_size('http://somesite.com/image.jpg', 'some alt text'); 
//result <img src="http://somesite.com/image.jpg" width="140" height="(proportionate to 140)" alt="(alt)" border="0">

November 4, 2009

MySQL, UPDATE data into a database using CONCAT()

Filed under: The Coding World — admin @ 2:46 pm

To insert data into a MySQL database while preserving the already existing data, you will just concatenate your new data to the end of your existing data.

Below is an example of how to do it using the column “changelog” which is used to keep track of changes made to the row/record.

View Code MYSQL
UPDATE table1 SET changelog=CONCAT(changelog,"new data") WHERE id='idnumber'

If you would like the data that you are entering to appear at the beginning of the existing data, simply flip the concatenation, example:

View Code MYSQL
UPDATE table1 SET changelog=CONCAT("new data",changelog) WHERE id='idnumber'

November 3, 2009

MySQL DELETE with a Max() Subquery

Filed under: The Coding World — admin @ 4:50 pm

Here is another nifty way to use a Subquery when deleting a record from your MySQL table.

View Code MYSQL
DELETE FROM table1 WHERE id = '1' && saleid='345' 
	                  && slot = (SELECT MAX(slot) FROM table1)

MySQL INSERT with a Max()+1 Subquery

Filed under: The Coding World — admin @ 4:47 pm

This was a pain in my ass to figure out so I figured I would post it here in case anyone else needs to insert a record using a Max()+1 Subquery.

I only use the Max()+1 Subquery when the value you want to increase is not the primary key.

View Code MYSQL
INSERT INTO table (row1, row2, row3)
    SELECT 1 + COALESCE((SELECT MAX(row1) FROM table), 0), 'value2', 'value3'
© - Digital Epiphany Designs, Online Portfolio for Web Design, Custom Programming, Grapic Design and Game Design.