mysql_fetch_array loop not working while result set contains rows
October 27, 2009
Last night I ran into the crazy problem that a mysql result set contained rows (confirmed with mysql_num_rows) but I wasn’t able to fetch the rows in mysql_fetch_array while loop construction. I managed to create a workaround but I posted a note on the php.net mysql_fetch_array page asking for an explanation. The note got rejected so I figured I could use my own blog in the search for an answer.
Here is the note;
I hope someone can help me with this question.
I have 2 code snippets. The first works, the second doesn’t. I would prefer using the second code snippet because it seems cleaner. What’s wrong with the second code snippet?
This works;
$results = mysql_query("SELECT DISTINCT(col) FROM table WHERE col!='' ORDER BY RAND()");
for( $i = 0; $i < mysql_num_rows( $results ); $i++ )
{
// do something with mysql_result($results,$i,0);
}
This doesn’t work;
$results = mysql_query("SELECT DISTINCT(col) FROM table WHERE col!='' ORDER BY RAND()");
while($result = mysql_fetch_array($results))
{
//do something with $result
}
PHP imagepng transparant turns black
October 24, 2009
I’m writing a web application that allows it’s users (among other things) to upload their company logos. PHP script is used to take the user provided jpgs/pngs and present them uniformly in a webpage. I ran into the problem that rescaled png images had their transparent regions turned black.
Here’s the solution I found;
- First create a new image (imagecreatetruecolor) with the required dimensions.
- Allocate a transparent color for that image. (imagecolorallocatealpha)
- Fill the image with the transparent color. (imagefilledrectangle)
- Now copy a scaled version of your original png image into the new image. (imagecopyresampled)
Voila.
Although the last step effectively overwrites all the pixels in your image, step 2 and 3 seem to be absolutely necessary to allow transparency inside your png image.
One more word of advice; use imagecopyresampled instead of imagecopyresized.
Resampled

Resampled "Dutch Design Award"
Resized

Resized "Dutch Design Award"
Fujitsu recommends Windows … ?
October 20, 2009
This commercial is about ….
A) a laptop with “Windows 7 Home Premium”
B) a laptop with “Windows Vista Home Premium”
Unexpected exception encountered while reading font file
October 18, 2009
I just had a weird unexpected exception thrown by the Flex 3.4 compiler on an existing ActionScript 3.0 project that always compiled without a problem.
exception during transcoding: Unexpected exception encountered while reading font file 'F.ttf' unable to build font 'F' Unable to transcode assets/F.ttf
Luckily I found solution via Google. Thanks Crazy Flexer “pixelfreak” adding -managers flash.fonts.AFEFontManager as an additional compiler argument fixed the build process.
Hope this blog post helps people that encounter the same issue.


