Monday, November 16, 2009

Mysql Joins - All records from left, One record from right table

t1 table


+----+--------+-------+
| id | name   | age   |
+-------------+-------+

|  1 |  kusal | 25    |
|  2 |  saman | 20    |
+----------+----+-----+



t2 table


+----------+----+------------+
| image_id | id | image_path |
+----------+----+------------+
|        1 |  1 | path1      |
|        2 |  1 | path2      |
|        3 |  1 | path 3     |
|        4 |  2 | path 1     |
|        5 |  1 | path 4     |
|        6 |  2 | path 5     |
+----------+----+------------+


SELECT * FROM t1 a left join t2 b on a.id = b.id group by b.id



+----+-------+-----+----------+------+------------+
| id | name  | age | image_id | id   | image_path |
+----+-------+-----+----------+------+------------+
|  1 | kusal |  25 |        1 |    1 | path1      |
|  2 | saman |  21 |        4 |    2 | path 1     |
+----+-------+-----+----------+------+------------+

Using group by for the right table id, it will only get the one result from right table.




Friday, June 26, 2009

Fix - Facebook profile application tab blank page

I think many new Facebook application developers face this problem. You do all the steps instructed in a book or the documentation and you still get a blank page for the profile tab. Yeah I know the feeling, It sucks big time, This error almost made me stop learning about Facebook app development.
After hours of searching and experimenting I found the solution for my problem.

Solution for my problem:

Canvas Callback URL should have a trailing /
Ex:
Canvas Callback URL: http://xxxxxx.joyent.us/

If you are using http://yourdomain/index.php just remove index.php since it will be loaded in default.

Wednesday, June 17, 2009

SEO Title Tag - 63 Characters or Low

In my opinion html title tag is most important thing in SEO optimization.
Creating meaningful and keyword specific titles is a must if you need a high rank in search engines.

Things to consider when writing web page titles
  1. Keep the title less than 63 (max: 70) characters.
  2. Put the important keywords in the front as possible.
  3. Putting the site name in the tilte is a choice you have to make with lot of thought. If you think that the site name has a good branding effect you can put the name at the end or front.
  4. Without using and, or, is try to use comma or |
  5. Don't use any meaningless words or special characters
  6. Never use duplicate titles on pages

Sunday, June 7, 2009

How to fix You don't have permission to access /phpmyadmin/ on this server Wamp

You don't have permission to access /phpmyadmin/ on this server (WAMP)
This is the message I got when I tried to access phpmyadmin after reinstalling WAMP server to a newer version. After some searching I was able to find the problem.

Reason:

When you uninstall your previous WAMP server there will be still few files that will be left not deleted and will not be replaced by the new install. One such file is the phpmyadmin.conf file that is under C:\wamp\alias folder. This file holds the actual path to the phpmyadmin folder inside WAMP.
If the new WAMP server has a new phpmyadmin version this phpmyadmin.conf will still point to the old folder which is not existing inside WAMP.

Solution:

goto C:\wamp\alias\ and edit the phpmyadmin.conf file using notepad


Alias /phpmyadmin "c:/wamp/apps/phpmyadmin2.11.6/"

# to give access to phpmyadmin from outside
# replace the lines
#
# Order Deny,Allow
# Deny from all
# Allow from 127.0.0.1
#
# by
#
# Order Allow,Deny
# Allow from all
#

<Directory "c:/wamp/apps/phpmyadmin2.11.6/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>



I just edited the c:/wamp/apps/phpmyadmin2.11.6/ with c:/wamp/apps/phpmyadmin3.1.3.1/
To find your new phpmyadmin folder goto C:\wamp\apps\


Alias /phpmyadmin "c:/wamp/apps/phpmyadmin3.1.3.1/"

# to give access to phpmyadmin from outside
# replace the lines
#
# Order Deny,Allow
# Deny from all
# Allow from 127.0.0.1
#
# by
#
# Order Allow,Deny
# Allow from all
#

<Directory "c:/wamp/apps/phpmyadmin3.1.3.1/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>



Now restart the WAMP server and try to access phpmyadmin

Saturday, June 6, 2009

Best Free php and Mysql web hosting with cPanel

000webhost offer completely ad-free cPanel web hosting.
No ads will ever be forced onto our users webpages.
There are no catches.
No setup fees.
No forced advertising.
No banners.
No popups
No hidden charges.
Only totally free hosting service.

Register now, here is what waiting for you:
* 1500 MB Disk Space
* 100 GB Data Transfer
* cPanel Control Panel
* Website Builder
* 5 MySQL Databases
* Unrestricted PHP5 support
* Instant Setup!

This service is perfect for starting a new online community, blog or personal website! More info at http://www.000webhost.com/171354.html

Tuesday, May 19, 2009

Create Dynamic Images with Text Using PHP GD

First check weather php gd library is enabled.


<?PHP

echo '<pre>';

print_r(gd_info());

echo '</pre>';

?>


If you get a error or a blank page that means the gd is not enabled in your server.
Contact your hosting and ask for php gd to be enabled.

Try following coding, everything is commented.


<?PHP

//save the arial.ttf font file in the same folder
$font = 'arial.ttf';
$fontsize = 10;

$YourText = 'Hi This Work';
$Text_Box = imagettfbbox($fontsize, 0, $font, $YourText);

//create image width 250, height 100
$image = imagecreatetruecolor(250,100);

//0,0,0 is black
$bgcolor = imagecolorallocate($image, 0, 0, 0);
//255, 255, 255 is white
$fontcolor = imagecolorallocate($image, 255, 255, 255);

//create a rectangle with the back ground coloe
imagefilledrectangle($image, 0, 0, 250, 100, $bgcolor);

$x = 10;
$y = 20;
//draw text on image
imagettftext($image, $fontsize, 0, $x, $y, $fontcolor, $font, $YourText);

//setting png headers
header('Content-type: image/png');
//create png image
imagepng($image);
//delete tempory files
imagedestroy($image);

?>



You can use this php file in a html file like this also


<img src="your_file_name.php" />

Sunday, May 17, 2009

phpMyAdmin mysql table overhead


If you are using phpmyadmin to manage mysql databases and tables you have probably seen a red figure for overhead in the space usage section in a table's detailed view.

This is a usual thing when you have lot of deletes and updates in your table fields. Think overhead as empty space and mysql want it to be defragmented. You can simply use the Optimize table link to get rid of the overhead.