MySQL JOIN single table on 2 fields

Use the following MySQL Query to Join Single Table on 2 relation fields :

SELECT a1.nama AS oleh_nama,
a2.nama as kpd,isi_disposisi, sifat, dikirim_pada,terbaca,id_surat,kpd_yth,oleh
FROM t_disposisi d
JOIN t_admin a1 ON (a1.id = d.oleh )
JOIN t_admin a2 ON (a2.id = d.kpd_yth)

Advertisements

Create Reverse DNS in WHM Cpanel (BIND)

Login to your WHM and choose add a DNS Zone:

for example our IP : 192.168.1.1-192.168.1.255

in the IP field  : enter your cpanel /WHM IP (192.168.1.1)
in the domain name : 1.168.192.in-addr.arpa

and then click submit , WHM will be creating the DNS Zone.

To add DNS PTR record entries to your reverse DNS zone:

in order to save your time by inputing the DNS PTR record manually  use the following entry :

$GENERATE 0-255 $ IN PTR xxx-xxx-xxx-$.domain.com.

Will cover a whole /24 with 1 line.

Replace xxx with your subnet. i.e IP-1-$.domain.com.

You can use $GENERATE entry in BIND/Named (not limited to WHM only)

PHP File Upload different File field Name

To upload a file / multiple files  usually we use the same file field name followed with array , for example :

What we need to do, if we want to use different file field name for each file : 

here’s the PHP trick so we can use different file field name:

foreach ($_FILES as $inputName => $uploadedFile) {
if(!empty($uploadedFile[‘name’])){
    echo $inputName, ‘:’ ,$uploadedFile[‘name’], PHP_EOL;
$tmp = $_FILES[$inputName][‘tmp_name’];
      $target_dir = “files/”;
      $target_file = $target_dir.basename($uploadedFile[‘name’]);

       //echo $target_file;
                     
if (move_uploaded_file($tmp, $target_file)){
                            echo ‘Click here to view the uploaded file.’;
                        }
                        else {
                            echo “Sorry, there was an error uploading your file”;
                        } }  

 $inputName variable contains each file field name 

Fix PhpMyAdmin Select command denied issue

Once our vestacp installation was finished, we had to import a file SQL , unfortunately phpadmin shipped by vestacp did not work properly with the following error:

#1142 – SELECT command denied to user ”@’localhost’ for table ‘pma_table_uiprefs’

A few suggestion to fix the issue, i decided to execute this command first before trying other solutions :

curl -O -k https://raw.githubusercontent.com/skurudo/phpmyadmin-fixer/master/pma-debian.sh && chmod +x pma-debian.sh && ./pma-debian.sh

Voila it works fine,  please note that command only working with debian . if you are using different linux distro , have  a look here :

https://github.com/skurudo/phpmyadmin-fixer

The script can be implemented however you don’t use vestacp , (not limited to vestacp version only )

Division Tips In PostgreSQL

In PostgreSQL , when trying divide a number the result is always wrong for example :

SELECT (30/50) as count_result;

and the result was zero (0), it should be 0,6 rather than 0. 

After further investigation , finally i found the following statement: 

Operations on integer arguments will return an integer result. To get
the value you’re expecting from that division, you’ll need to cast one
of the numbers to a floating point type.

Therefore if you want to product the result you wanted , here’s the corrected Query


select cast(30 as real) / 50;
select cast(30 as numeric) / 50;
select 30::real / 50;
select 30 / 50::float;

Please comment below, if you find it helpful 🙂 

Increase Linux Non LVM Partition Size online with Parted

If you are looking the way to increase your linux partition online, you should read below , please backup your data first .

umount /boot

parted /dev/sdb

(parted) print

Model: ATA Patriot Torqx 2 (scsi)

Disk /dev/sdb: 32.0GB Sector size (logical/physical): 512B/512B

Partition Table: msdos

Number Start End Size Type File system Flags

1 1049kB 12.9GB 12.9GB primary type=83

2 12.9GB 13.0GB 107MB primary ext4 type=83

          (parted) rm 2

(parted) mkpart

Partition type? primary/extended?

primary File system type? [ext2]?

Start? 12.9GB

End ? 13.4GB

(parted) quit

resize2fs /dev/sdb2

resize2fs 1.42.6 (21-Sep-2012) Filesystem at /dev/sdb2 is mounted on /boot; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 2 The filesystem on /dev/sdb2 is now 498688 blocks long. done!

All data remains in place. /boot is ready for use and 472MB big (parted is not that secure with the sizes, read the manual to know why) All data was backed up before, but only as a precaution. I recommend to do the same.
 Use the following command to find the process which is stopping the unmounting of /boot if it fails:

 lsof /boot 

Good luck!