Archive for กรกฎาคม, 2009

Drag & Drop with PHP & jQuery

The ability to drag and drop content on a page and have it save the order can make for a great user interface and is actually relatively easy to execute with a few lines of jQuery. You’ll need to include the jQuery user interface library which you can find here: Jquery Google API. All the files needed to get this up and running are in the download at the bottom of this post.

In this tutorial we’re going to be looking at 2 main PHP pages. the index.php page which contains the contents and functionality to perform the drag and drop and the updateList.php file which is a simple piece of code to update the listOrder column in the database using PHP and MySQL. Additionally you will need to add your database details to the connect.php file in the download package.


$(document).ready(function(){
	  function slideout(){
  setTimeout(function(){
  $("#response").slideUp("slow", function () {
      });

}, 2000);}

    $("#response").hide();
	$(function() {
	$("#list ul").sortable({ opacity: 0.8, cursor: 'move', update: function() {

			var order = $(this).sortable("serialize") + '&update=update';
			$.post("updateList.php", order, function(theResponse){
				$("#response").html(theResponse);
				$("#response").slideDown('slow');
				slideout();
			});
		}
		});
	});

});

Here’s a summary of whats going on in the code above.

1. To start with we have a simple function that will slide up the ‘response’ div which contains the message once the data is saved in the database.
2. We then move to the section that enables us to drag and drop the boxes. we then set the variable ‘order’ which contains the data to be posted via ajax to our database update script.
3. Once the ajax request has been executed we then display the response in the div #response

This is the section in the index.php page that retrieves the results from the database in the correct order.


 <div id="list">

    <div id="response"> </div>
    <ul>
      <?php
                include("connect.php");
				$query  = "SELECT id, text FROM dragdrop ORDER BY listorder ASC";
				$result = mysql_query($query);
				while($row = mysql_fetch_array($result, MYSQL_ASSOC))
				{

				$id = stripslashes($row['id']);
				$text = stripslashes($row['text']);

				?>
      <li id="arrayorder_<?php echo $id;?>"><?php echo $id;?> <?php echo $text;?>
        <div class="clear"></div>
      </li>
      <?php } ?>
    </ul>
  </div>

Below is the code from the ‘updateList.php’ file. Its pretty self explanatory, we have a MySQL update script wrapped with a foreach loop which adds the list order number in the database and echo’s the response.


<?php
include("connect.php");
$array	= $_POST['arrayorder'];
if ($_POST['update'] == "update"){
$count = 1;
	foreach ($array as $idval) {
		$query = "UPDATE dragdrop SET listorder = " . $count . " WHERE id = " . $idval;
		mysql_query($query) or die('Error, insert query failed');
		$count ++;
	}
	echo 'All saved! refresh the page to see the changes';
}
?>
  • Comments Off

Load-Balanced MySQL Cluster
สืบเนื่องมาจากการทำ MySQL Cluster เสร็จแล้ว เราลองมาต่อยอดด้วยการทำ Load-Balance สำหรับ MySQL Cluster กันดู
ลักษณะการทำงานของ Load Balance
คือ การจัดกลุ่มของคอมพิวเตอร์หลายๆตัวเพื่อแบ่งงานกัน หรือกระจาย load การใช้งานของ user ไปยังคอมพิวเตอร์ภายในกลุ่ม เพื่อให้สามารถรับจำนวน user ที่เข้ามาใช้งานได้มากขึ้น หรือสามารถรับงานที่เข้ามาได้มากขึ้น นอกจากนั้นยังมีคุณสมบัติของ Fail Over คือหากมีคอมพิวเตอร์ภายในกลุ่มไม่สามารถทำงานได้ เช่น Down อยู่ หรือไม่สามารถรับงานหรือ user เพิ่มได้เนื่องจาก resource ที่ใช้ทำงานไม่พอ ตัว Load Balancer ที่เป็นตัวแจก load ให้คอมพิวเตอร์ภายในกลุ่มก็จะส่ง load ไปยังคอมพิวเตอร์เครื่องอื่นๆแทน จนกว่าคอมพิวเตอร์เครื่องนั้นจะกลับมาใช้งานได้ใหม่

ตัว load balancer อาจเกิดปัญหา bottleneck แล้วจะเกิดอะไรขึ้นถ้า load balancer fail ขึ้นมา ดังนั้นในที่นี้เราจะให้มี load balancer 2 ตัว โดย load balancer ทั้ง 2 ตัวจะมีตัวใดตัวหนึ่งมีสถานะเป็น active และตัวที่เหลือจะมีสถานะเป็น passive ซึ่งหมายความว่าจะมีหนึ่ง active load balancer และอีกตัวหนึ่งเป็น hot-standby load balancer โดยจะกลายเป็น active เมื่อตัวที่เป็น active fail

หมายเหตุ ขอปรับเปลี่ยน API node ให้เป็น Load Balancer ตัวที่2 แทน เนื่องจากในการทำ load balance ไม่จำเป็นที่จะต้องใช้ API node ซึ่งขั้นตอนการปรับเปลี่ยน API node เพื่อเตรียมเป็น Load Balancer 2 มีดังนี้
ขั้นตอนที่ 1 ทำการตรวจสอบสถานะของ cluster บน MySQL cluster management server / Load Balancer1 (sqlmang:192.168.0.4) ดังนี้


sqlmang:192.168.0.4
ndb_mgmndb_mgm> show;
Cluster Configuration
———————
[ndbd(NDB)]     2 node(s)

id=2    @192.168.0.1  (Version: 5.0.38, Nodegroup: 0)
id=3    @192.168.0.2  (Version: 5.0.38, Nodegroup: 0, Master)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.0.4  (Version: 5.0.38)

[mysqld(API)]   3 node(s)
id=4    @192.168.0.2  (Version: 5.0.38)
id=5    @192.168.0.1  (Version: 5.0.38)
id=6    @192.168.0.3  (Version: 5.0.38)

ขั้นตอนที่ 2 ลบ [MYSQLD] ออกจาก file /var/lib/mysql-cluster/config.ini บน MySQL cluster management server / Load Balancer1 (sqlmang:192.168.0.4) ดังนี้


sqlmang:192.168.0.4
cd /var/lib/mysql-cluster
pico config.ini

ขั้นตอนที่ 3 แก้ไข file /etc/mysql/my.cnf บน sqlload:192.168.0.3 ดังนี้


sqlload:192.168.0.3
cd /etc/mysql
pico my.cnf 

#ใส่เครื่องหมาย # หน้าบรรทัด ndbcluster และ ndb-connectstring=192.168.0.4


#ndbcluster
#ndb-connectstring=192.168.0.4
[MYSQL_CLUSTER]
#ndb-connectstring=192.168.0.4

ขั้นตอนที่ 4 restart service MySQL บน sqlload:192.168.0.3 ดังนี้


sqlload:192.168.0.3
/etc/init.d/mysql restart

ขั้นตอนที่ 5 restart cluster บน MySQL cluster management server / Load Balancer1
(sqlmang:192.168.0.4) ดังนี้


sqlmang:192.168.0.4
ndb_mgm
ndb_mgm> shutdown;
Node 2: Cluster shutdown initiated
Node 3: Cluster shutdown initiated
Node 2: Node shutdown completed.
2 NDB Cluster node(s) have shutdown.
Disconnecting to allow management server to shutdown.
ndb_mgm> quit;
ndb_mgmd -f /var/lib/mysql-cluster/config.ini 

sqlnode1:192.168.0.1/sqlnode2:192.168.0.2
ndbd – initial

ขั้นตอนที่ 6 ตรวจสอบสถานะของ cluster บน MySQL cluster management server / Load Balancer1(sqlmang:192.168.0.4) อีกครั้ง ดังนี้


sqlmang:192.168.0.4
ndb_mgmndb_mgm> show;
Cluster Configuration
———————
[ndbd(NDB)]     2 node(s)
id=2    @192.168.0.1  (Version: 5.0.38, Nodegroup: 0, Master)
id=3    @192.168.0.2  (Version: 5.0.38, Nodegroup: 0)[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.0.4  (Version: 5.0.38) [mysqld(API)]   2 node(s)
id=4    @192.168.0.2  (Version: 5.0.38)
id=5    @192.168.0.1  (Version: 5.0.38) ndb_mgm> quit;

นอก จากนี้ Load balancer ทั้ง 2 จะใช้ heartbeat ในการตรวจสอบว่า load balancer อีกตัวยังทำงานได้ตามปกติหรือไม่ และ load balancer ทั้งคู่จะใช้ ldirectord เพื่อเป็นตัวแบ่งการทำงานออกไปยัง cluster node
เมื่อเรา install Ultra Monkey package ก็จะมีการ install ทั้ง heartbeat และ ldirectord ให้โดยอัตโนมัติ

สรุป การทำระบบ Load-Balanced MySQL Cluster ครั้งนี้จะใช้เครื่องทั้งหมด จำนวน 4 เครื่องดังนี้
เครื่องที่1 : เป็น storage node หรือ cluster node (sqlnode1:192.168.0.1)
เครื่องที่2 : เป็น storage node หรือ cluster node (sqlnode2:192.168.0.2)
เครื่องที่3 : เป็น Load Balancer 2 (sqlload:192.168.0.3)
เครื่องที่4 : เป็น MySQL cluster management server / Load Balancer1 (sqlmang:192.168.0.4)
และใช้ virtual IP address เป็น 192.168.0.5

Install Ultra Monkey
เริ่ม ต้นเราต้อง enable IPVS (IP Virtual Server) บน Load Balancer1(sqlmang:192.168.0.4) และ Load Balancer2(sqlload:192.168.0.3) ดังนี้


sqlmang:192.168.0.4/ sqlload:192.168.0.3
modprobe ip_vs_dh
modprobe ip_vs_ftp
modprobe ip_vs
modprobe ip_vs_lblc
modprobe ip_vs_lblcr
modprobe ip_vs_lc
modprobe ip_vs_nq
modprobe ip_vs_rr
modprobe ip_vs_sed
modprobe ip_vs_sh
modprobe ip_vs_wlc
modprobe ip_vs_wrr

ในกรณีที่ต้องการให้มีการ load IPVS kernel modules ขณะที่มีการ boot เครื่อง ทำได้ดังนี้


pico /etc/modules

จากนั้นให้เพิ่ม Ultra Monkey respository ต่อท้ายของเดิมที่มีอยู่ ที่ /etc/apt/sources.list แล้ว install Ultra Monkey


sqlmang:192.168.0.4/ sqlload:192.168.0.3
pico  /etc/apt/sources.list

apt-get update
apt-get install ultramonkey libdbi-perl libdbd-mysql-perl libalps-heap1-dev
dev 

เรา ต้อง install MySQL เพื่อให้สามารถใช้งาน DBD::mysql Perl ได้ (ถ้าเครื่องไหนได้ install mysql-server แล้ว ไม่ต้องทำขั้นตอนนี้ใหม่)


sqlmang:192.168.0.4/ sqlload:192.168.0.3
cd /tmp
sudo apt-get install mysql-server 

จากนั้นเปิดให้มีการใช้งาน packet forwarding


sqlmang:192.168.0.4/ sqlload:192.168.0.3
pico /etc/sysctl.conf

sysctl - p
จะแสดงผล
kernel.printk = 4 4 1 7
net.ipv4.conf.default.forwarding = 1
Configure heartbeat
ใน การ configure heartbeat เราจะต้องสร้าง file ขึ้นมา 3 file บน Load Balancer1(sqlmang:192.168.0.4) และ Load Balancer2 (sqlload:192.168.0.3) ซึ่งได้แก่ file ha.cf file haresources และfile authkeys ดังนี้
sqlmang:192.168.0.4/ sqlload:192.168.0.3
pico /etc/ha.d/ha.cf

คำสั่งสำหรับแสดงรายชื่อ node คือ uname –n
pico /etc/ha.d/haresources

ใน file นี้เราต้องใส่ชื่อ node ของ Load Balance1 และใส่ virtual IP address ซึ่งในที่นี้ใช้ 192.168.0.5 พร้อมทั้ง netmask (27) และ broadcast address (192.168.0.31)

pico /etc/ha.d/authkeys

ซึ่ง somerandomstring คือ password ที่จะใช้เชื่อมต่อระหว่าง heartbeat บน LoadBalance1(sqlmang:192.168.0.4) และ Load Balance2 (sqlload:192.168.0.3)

จากนั้นกำหนดสิทธิ์ให้ root เท่านั้นที่สามารถอ่าน file authkeys ได้
chmod 600 /etc/ha.d/authkeys

Configure ldirectord
เริ่ม ต้นสร้าง configuration file ldirectord.cf สำหรับ ldirectord บน Load Balancer1(sqlmang:192.168.0.4) และ Load Balancer2(sqlload:192.168.0.3)
sqlmang:192.168.0.4/ sqlload:192.168.0.3

pico /etc/ha.d/ldirectord.cf

ซึ่ง ค่า login ค่า passwd ค่า database และค่า resquest ที่เรากำหนดใน file ldirectord.cf นี้ ขึ้นอยู่กับที่เราสร้างใน MySQL ซึ่งจะกล่าวถึงในหัวข้อ Create A Database Called ldirector

จาก นั้น create system startup link สำหรับ heartbeat และ remove system startup link ของ ldirectord ที่มีอยู่ออก(เพราะว่า ldirectord จะถูก start ด้วย heartbeat) ดังนี้
update-rc.d -f heartbeat remove

จะปรากฎข้อความ
Removing any system startup links for /etc/init.d/heartbeat …
/etc/rc0.d/K05heartbeat
/etc/rc1.d/K05heartbeat
/etc/rc2.d/S75heartbeat
/etc/rc3.d/S75heartbeat
/etc/rc4.d/S75heartbeat
/etc/rc5.d/S75heartbeat
/etc/rc6.d/K05heartbeat

update-rc.d heartbeat start 75 2 3 4 5 . stop 05 0 1 6 .
จะปรากฎข้อความ
Adding system startup for /etc/init.d/heartbeat …
/etc/rc0.d/K05heartbeat -> ../init.d/heartbeat
/etc/rc1.d/K05heartbeat -> ../init.d/heartbeat
/etc/rc6.d/K05heartbeat -> ../init.d/heartbeat
/etc/rc2.d/S75heartbeat -> ../init.d/heartbeat
/etc/rc3.d/S75heartbeat -> ../init.d/heartbeat
/etc/rc4.d/S75heartbeat -> ../init.d/heartbeat
/etc/rc5.d/S75heartbeat -> ../init.d/heartbeat

update-rc.d -f ldirectord remove
จะปรากฎข้อความ
Removing any system startup links for /etc/init.d/ldirectord …

Create A Database Called ldirector
เรา จะสร้าง database ชื่อ “ldirectordb” บน MySQL Cluster node ทั้งสอง (sqlnode1:192.168.0.1 และ sqlnode2:192.168.0.2) ซึ่งเป็น database ที่ load balancer ใช้ตรวจสอบว่า MySQL cluster node ยังทำงานอยู่หรือไม่


sqlnode1:192.168.0.1
mysql -u root –p
GRANT ALL ON ldirectordb.* TO ‘ldirector’@’%’ IDENTIFIED BY ‘ldirectorpassword’;
FLUSH PRIVILEGES;
CREATE DATABASE ldirectordb;
USE ldirectordb;
CREATE TABLE connectioncheck (i INT) ENGINE=NDBCLUSTER;
INSERT INTO connectioncheck () VALUES (1);
quit;  

sqlnode2:192.168.0.2
mysql -u root –p
GRANT ALL ON ldirectordb.* TO ‘ldirector’@’%’ IDENTIFIED BY ‘ldirectorpassword’;
FLUSH PRIVILEGES;
CREATE DATABASE ldirectordb;
quit;  

Prepare The MySQL Cluster Nodes For Load Balancing
เรา ต้อง configure ให้ MySQL cluster node ทั้งสอง (sqlnode1:192.168.0.1 และ sqlnode2:192.168.0.2) รับการร้องขอ (request) จาก virtual IP address (192.168.0.5)
sqlnode1:192.168.0.1/ sqlnode2:192.168.0.2
apt-get install iproute

จากนั้นแก้ไข file sysctl.conf ที่ /etc/sysctl.conf (เพิ่มข้อความด้านล่างนี้ต่อท้ายของเดิม)
pico /etc/sysctl.conf

sysctl -p
จากนั้นแก้ไข interfaces สำหรับรองรับ virtual IP address (192.168.0.5)
pico /etc/network/interfaces

ifup lo:0

Start The Load Balancer
เริ่มต้น start heartbeat บน Load Balancer ทั้งสอง (sqlmang:192.168.0.4 และ sqlload:192.168.0.3) ดังนี้sqlmang:192.168.0.4/sqlload:192.168.0.3
/etc/init.d/heartbeat start

ถ้าไม่มี error เกิดขึ้น ให้ reboot load balancer ทั้งสองตัว โดยใช้คำสั่ง
shutdown – r now

ภายหลังจากที่ reboot load balancer ทั้งสองตัวเสร็จ ให้ตรวจสอบการทำงานของ load balancer โดยsqlmang:192.168.0.4/sqlload:192.168.0.3
ip addr sh eth0

จะปรากฎข้อความในกรณีที่เป็น active Load Balancer
2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:01:29:4b:54:0b brd ff:ff:ff:ff:ff:ff
inet 192.168.0.4/27 brd 192.168.0.31 scope global eth0
inet 192.168.0.5/27 brd 192.168.0.31 scope global secondary eth0
และจะปรากฎข้อความในกรณีที่เป็น hot-standby Load Balancer
2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0b:cd:94:cf:06 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.3/27 brd 192.168.0.31 scope global eth0

sqlmang:192.168.0.4/sqlload:192.168.0.3
ldirectord ldirectord.cf status

จะปรากฎข้อความในกรณีที่เป็น active Load Balancer
ldirectord for /etc/ha.d/ldirectord.cf is running with pid: 5801
และจะปรากฎข้อความในกรณีที่เป็น hot-standby Load Balancer
ldirectord is stopped for /etc/ha.d/ldirectord.cf

sqlmang:192.168.0.4/sqlload:192.168.0.3
ipvsadm -L –n

จะปรากฎข้อความในกรณีที่เป็น active Load Balancer
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.100.22:3306 wrr
-> 192.168.100.20:3306 Route 1 0 0
-> 192.168.100.19:3306 Route 1 0 0
และจะปรากฎข้อความในกรณีที่เป็น hot-standby Load Balancer
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn

sqlmang:192.168.0.4/sqlload:192.168.0.3
etc/ha.d/resource.d/LVSSyncDaemonSwap master status
จะปรากฎข้อความในกรณีที่เป็น active Load Balancer
master running
(ipvs_syncmaster pid: 5951)

และจะปรากฎข้อความในกรณีที่เป็น hot-standby Load Balancer
master stopped
(ipvs_syncbackup pid: 6072)

Testing (การทดสอบ)
สำหรับ การทดสอบ เราจะให้มีการเรียก connect database จากเครื่องอื่นที่อยู่ภายในวง network เดียวกัน ผ่านทาง virtual IP address (192.168.0.5) ที่เรากำหนดไว้ ดังนี้
C:\Documents and Settings\Administrator>mysql -h 192.168.100.22 -u ldirector –p
Enter password: *****************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 917500 to server version: 5.0.38-Ubuntu_0ubuntu1-log

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql>

หมายเหตุ
1. เมื่อมีการ run คำสั่ง ip addr sh eth0 แล้วปรากฎ inet6 fe80:20b:cdff:fe94:of06 /64 scope link(ให้แก้ไขที่ Load Balance ทั้ง 2 ตัว)
- pico /etc/modprobe.d/aliases
- ให้หาบรรทัด alias net-pf-10 ipv6 แล้วแก้ไขเป็น alias net-pf-10 off
- ให้ save file และทำการ reboot โดยใช้คำสั่ง “ifdown -a” และตามด้วย “ifup -a”
2. ในกรณีใช้คำสั่ง ipvsadm –L –n แล้วตรง ส่วน Route ไม่แสดงเลข 1 แนะนำให้ไปตรวจสอบ bindaddress และ usr % (สำหรับ Load Balancer)

Reference :
[1] www.narisa.com/forums/index.php?showtopic=6466
[2] http://www.howtoforge.com/loadbalanced_mysql_cluster_debian

  • Comments Off

jQuery UI Sortable with TABLE

Drag and drop sorting on a web application? This thought is so far fetched several years ago - and now everybody is or can do that easily with jQuery. Looking at the tutorials and documentation in jQuery’s website, it lays out a simple method to call to make our list to become sortable.


$(function() {
   $("#sortable").sortable();
   $("#sortable").disableSelection();
});

With our corresponding HTML:


<ul id="sortable">
    <li>one</li>
    <li>two</li>
    <li>three</li>
    <li>four</li>
</ul>

Here is a demo on how that works.
Now what if we are using TABLE instead of UL or OL??

Easy - Use TBODY tag. So using the example above, let’s convert the list into a table:


<table id=anothersortable>
    <tbody class=content>
        <tr><td>one</td></tr>
        <tr><td>two</td></tr>
        <tr><td>three</td></tr>
        <tr><td>four</td></tr>
    </tbody>
</table>
[sourcecode]

Then our jQuery to be as such:
[sourcecode language="php"]
$(function() {
    $("#anothersortable tbody.content").sortable();
    $("#anothersortable tbody.content").disableSelection();
});
[sourcecode]
Click for demo for the simple table.
You can even make this having sub-sort - or with children sorting. Like this:
[sourcecode language="php"]
<table id=subsortsortable>
    <tbody class=content>
        <tr><td>one</td></tr>
        <tr><td>two</td></tr>
        <tr><td>
            <table><tbody class=subcontent>
                <tr><td>three.one</td></tr>
                <tr><td>three.two</td></tr>
            </tbody></table>
        </td></tr>
        <tr><td>four</td></tr>
    </tbody>
</table>

Adjust our jQuery to be as such:


$(function() {
   $("#subsortsortable tbody.content").sortable();
    $("#subsortsortable tbody.content").disableSelection();
     $("tbody.subcontent").sortable();
    $("tbody.subcontent").disableSelection();
});

Click for demo of this one.

  • Comments Off

While we were working on http://www.duettographics.com Administration control panel, they required the ability to sort their images in easy way, so after some googeling we find many separate tutorials for this. So, we decided to write one simple tutorial that can describe the whole thing.

In this tutorial, we’ll work on sorting menu items.

Requirements : sortable jQuery UI, PHP & MySQL server support.

  1. Create a new MySQL Database called `test_db` and a new table called `menu
    CREATE TABLE IF NOT EXISTS `menu` (
      `id` int(11) NOT NULL auto_increment,
      `title` int(11) NOT NULL,
      `sort` int(2) NOT NULL,
      PRIMARY KEY  (`id`)
    )
  2. Create new php file called “menu_list.php”, this file will be our main file to sort the menu items .

    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Sorting Items on the fly using jQuery UI, PHP &amp;amp;amp;amp; MySQL</title>
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.7.1.custom.min.js"></script>
    <script>
    $(document).ready(
    function() {
    $("#sortme").sortable({
    update : function () {
    serial = $('#sortme').sortable('serialize');
    $.ajax({
    url: "sort_menu.php",
    type: "post",
    data: serial,
    error: function(){
    alert("theres an error with AJAX");
    }
    });
    }
    });
    }
    );
    </script>
    </head>
    <body>
    <h1>Menu List</h1>
    
    <ul id="sortme">
    <?php
    // Connecting to Database
    mysql_connect($hostname, $user_name, $password) or die ('Cant Connceto to MySQL');
    
    // Selecting Database
    mysql_select_db($db_name) or die ('Cant select Database');
    
    // Getting menu items from DB
    $result = mysql_query("SELECT * FROM `menu` ORDER BY `sort` ASC") or die(mysql_error());
    while($row = mysql_fetch_array($result)) {
    echo '<li id="menu_' . $row['id'] . '">' . $row['title_en'] . "</li>\n";
    }
    ?>
    </ul>
    </body>
    </html>
    

    Create a new file for AJAX purpose to update sorting called “sort_menu.php”

    
    <?php
    // Connecting to Database
    mysql_connect($hostname, $user_name, $password) or die ('Cant Connceto to MySQL');
    
    // Selecting Database
    mysql_select_db($db_name) or die ('Cant select Database');
    
    $menu = $_POST['menu'];
    for ($i = 0; $i < count($menu); $i++) {
    mysql_query("UPDATE `menu` SET `sort`=" . $i . " WHERE `id`='" . $menu[$i] . "'") or die(mysql_error());
    }
    ?>
    

    Finally, this should works fine with you, but If you faced any

  • Comments Off

Asterisk Fax bash script

For sending faxes through asterisk (once successfully set up) is very easy. You can make it do some funky things. To test to see if it works though I wrote this quick script;

#!/bin/sh
#
# Work fax number = 01618771111
#

FAXDATE=`date +%s-%N`
cat <<EOF >/tmp/fax-$FAXDATE.call
Channel: SIP/fax/01618771111
MaxRetries: 1
WaitTime: 20
Set: LOCALSTATIONID=Company Name
Set: LOCALHEADERINFO=Department
Set: REMOTESTATIONID=0161100000
Application: txfax
Data: /var/spool/asterisk/fax/11158588-200709211145.tiff|caller
EOF

mv /tmp/fax-$FAXDATE.call /var/spool/asterisk/outgoing/
  • Comments Off

miniPE เอาชุดนี้ใส่เข้าไปในUSB Flash Driveได้หรือไม่ เพราะขณะนี้ราคาของสินค้าตัวนี้ลดลงมาก 1 จิ ราคาพันกว่าบาทเท่านั้น ก็เป็นทางเลือกอีกทางหนึ่งสำหรับที่จะนำชุด miniPE ทั้งหลายติดตัวไปได้สะดวกขึ้น ผมมาหาข้อมูลวิธีทำมันมีอยู่ครับไม่ยากเลยครับ มันง่ายจนนึกไม่ถึงครับ ในที่นี่ ผมจะกล่าวถึงวิธีทำอยู่ 3 วิธี มาเริ่มกันเลยครับ

สิ่งที่ต้องใช้

1.แผ่น miniPE หรือไฟล์ ISO ของ miniPE ที่คุณใช้อยู่ ซึ่งไม่จำเป็นต้องเป็นชุด augiePE ที่ผมทำแจกครับ ใช้ชุดของ miniPE-XT 2k5.09.03 ของ Digiwiz หรือจะเป็นชุดอื่นๆที่ใช้หลักเดียวกันก็ได้ เช่น XPE ทั้งภาษาจีนและอังกฤษ หรือ ERD Commander 2003-2005 ผมได้ทดลองแล้วก็ใช้ได้ครับ

2.USB Flash Drive (ต่อไปในบทความผมจะขอเรียกว่า “UFD” ) ที่มีขนาดความจุมากกว่าชุด miniPE ที่จะใช้

3.โปรแกรมที่จะช่วยในการทำซึ่งจะมีอยู่ 3 โปรแกรม ซึ่งแต่ละตัวที่จะใช้ก็อยู่ที่วิธีการทำที่คุณๆ จะเลือกใช้วิธีใด

-HP USB Disk Storage Format Tool โปรแกรมช่วย Format ไปดาวน์โหลดได้ ที่นี่ี่่ http://www.box.net/public/n9payyr4oo หรือที่นี่ http://www.4shared.com/file/1908005/1f4eb93b/sp27213.html

-UltraISO โปรแกรมอ่านเขียนไฟล์ ISO ดาวน์โหลด ที่นี่ี่ http://www.ezbsystems.com/ultraiso/

-PEtoUSB โปรแกรมอีกตัวที่ช่วยทำ miniPE ฉบับ USB Flash Drive ไปดาวน์โหลด ที่นี่ http://gocoding.com/page.php?al=petousb (PeToUSB_3.0.0.7.zip)

เริ่มลงมือปฎิบัติการ

วิธีที่ 1 สิ่งที่ต้องใช้ได้แก่ โปรแกรม HP USB Disk Storage Format Tool และแผ่นซีดี miniPE

1 ทำการติดตั้งไฟล์ SP27213.exe ก็จะได้ HP USB Disk Storage Format Tool โดยจะมีไอคอนของโปรแกรมปรากฎขึ้นที่หน้า Desktop เอา UFD ของคุณติดตั้งที่ช่องรับ USB ของคอมพิวเตอร์

2. ให้คับเบิลคลิกที่ไอคอนของโปรแกรมเพื่อเรียกออกมาใช้งาน หน้าตาก็จะได้ตามรูป ให้คุณ Format โดยจะเลือกแบบ FAT หรือ FAT32 ก็ได้ และ format แบบ Quick Format คือไม่เอา System Files เพราะจะเอาจากแผ่น miniPE แทน

3.ให้นำแผ่น miniPE ที่จะใช้ใส่ในซีดีไดรฟ์ ทำการก็อปปี้ไฟล์ทั้งหมดในแผ่นมาไว้ที่ UFD

คลิกเพื่อดูภาพขนาดจริง

4.เมื่อก็อปปี้ไฟล์ทั้งหมดมาที่ UFD แล้ว มาถึงขั้นตอนที่ปรับแต่ง UFD เพื่อให้ทำการบูตได้ ให้ทำการเปลื่ยนชื่อโฟลเดอร์ “\I386″ เป็น “\minint”

5.ก็อปปี้ไฟล์ ntdetect.com ที่อยู่ใน \minint มาไว้ที่ ไดเร็กทอรี่รากของ UFD

6.ก็อปปี้ไฟล์ setupldr.bin ที่อยู่ใน \minint มาไว้ที่ ไดเร็กทอรี่รากของ UFD

7.ทำการเปลื่ยนชื่อไฟล์ setupldr.bin ที่ก็อปปี้มาตามข้อ 6 เป็นชื่อ “ntldr” โดยไม่มีนามสกุลต่อท้าย

คลิกเพื่อดูภาพขนาดจริง

คลิกเพื่อดูภาพขนาดจริง

วิธีที่ 2 สิ่งที่ต้องใช้ได้แก่ โปรแกรม HP USB Disk Storage Format Tool และ UltraISO และ ไฟล์ ISO ของชุด miniPE

1.ให้ทำตามข้อ 1 และ 2 ในวิธีที่ 1

2.ให้เปิดโปรแกรม UltraISO ขึ้นมาในกรณีเครื่องมีอยู่แล้ว (ถ้าไม่มีก็ดาวน์โหลดมาติดตั้งซะให้เรียบร้อย) ให้เปิดไฟล์ ISO ของ miniPE โดยไปที่ File > Open

คลิกเพื่อดูภาพขนาดจริง

3.เมื่อเปิดไฟล์มาแล้วจะเห็นไฟล์ทั้งหมดที่หน้าต่างบนของโปรแกรม ให้คลิกขวาที่ไฟล์ใดไฟล์หนึ่งเลือกคำสั่ง Select All โปรแกรมจะทำ Highlight ไฟล์ทั้งหมด ให้คลิกขวาที่ Highlight เลือกคำสั่ง Extract to…ให้เลือกไปที่ UFD

4.เมื่อทำการขยายไฟล์จาก ISO มาที่ UFD เสร็จแล้ว ก็ให้ทำตามข้อ 4 ถึง 7 ของวิธีที่ 1

วิธีที่ 3 สิ่งที่ต้องใช้ได้แก่ โปรแกรม PEtoUSB และแผ่นซีดี miniPE

PEtoUSB เป็นโปรแกรมที่ออกแบบมาเพื่อทำใหัชุด miniPE ให้ใช้บน UFD โดยเฉพาะใช้ง่ายครับโปรแกรมจะทำการ Format ก็อปปี้ไฟล์ เปลื่ยนชื่อไฟล์และโฟลเดอร์เสร็จในคราวเดียว ตัวโปรแกรมยังมีทูลและมีฟังก์ชั่นอื่นๆ อีก แต่ในที่นี่ขอกล่าวถึงจุดประสงค์หลักของบทความนี้ก็พอ ถ้าอยากทราบรายละเอียดมากกว่านี้ไปศึกษาได้ที่ http://gocoding.com

1.เมื่อดาวน์โหลดโปรแกรมมาแล้วให้ขยายไฟล์ออกมาจะได้ไฟล์ 3 ไฟล์ ไม่ต้องติดตั้งให้ดับเบิลคลิกที่ไฟล์ PeToUSB.exe โปรแกรมจะเปิดขึ้นมาตามรูป

2.ให้คุณเอาแผ่น miniPE ใส่ในไดรฟ์เตรียมไว้ พร้อมทั้งติดตั้ง UFD ที่ช่อง USB เริ่มทำตามขั้นตอนตามนี้

-A. คลิกเลือก USB Removable จะเห็น UFD ของคุณ ถ้าไม่เห็นให้คลิก Refresh

-B.คลิกทำเครื่องหมายที่ Enable Disk Format

-C..คลิกทำเครื่องหมายที่ Quick Format ตรงช่อง Drive Label ใส่ชื่อตามใจชอบ

-D.คลิกหาไดรฟ์ที่ใส่แผ่น miniPE

-E.คลิกทำเครื่องหมายที่ Enable File Copy

-F.คลิกเลือก Overwrite Always และคลิก Start ให้โปรแกรมทำงาน

ผ่านไปครับสำหรับวิธีทำให้ UFD สามารถบูต miniPE ได้ ไม่ยากเลยนะครับทั้ง 3 วิธี ใครชอบวิธีไหนก็ลองดูครับ ตอนก็มาถึงส่วนสำคัญที่สุดของงานนี้ นั้นคือทำให้คอมพิวเตอร์มันย่อมรับ UFD ก็ต้องไปดูว่า BIOS ของเครื่องนั้นมี Option ที่รับการบูตด้วย UFD หรือไม่ วิธีการได้แก่

1.ก่อนเปิดเครื่องให้ใส่่ UFD ในช่อง USB ก่อน

2.เปิดเครื่องในช่วงเครื่องกำลังแสดงที่หน้าจอหรือได้ยินเสียง “ติ้ด” ให้กด Del หลายครั้งเพื่อเข้า BIOS (ให้ดูคู่มือของเครื่องหรือเมนบอร์ดว่าใช้ปุ่มไหน แต่เครื่องส่วนใหญ่จะใช้ปุ่มนี้)

3.เมื่อเข้า BIOS ได้แล้วให้หาหัวข้อ BOOT หรือ Boot Device Priority มันจะอยู่ประมาณข้อหัวแบบนี้ หาดูว่ามีให้บูตด้วย USB-HDD หรือ USB-ZIP หรือไม่ ถ้ามีก็ใช้ได้ครับให้ตั้งเป็นบูตไดรฟ์แรกเลย เสร็จแล้วก็เซฟ BIOS เครื่องจะบูตใหม่ ถ้าไม่มีอะไรผิดผลาดเครื่องก็จะบูตจาก UFD และก็จะได้ miniPE ฉบัับ USB Flash Drive ไว้ใช้งาน

UFD ที่ผมใช้ในการทดลองทำสำหรับบทความนี้ ผมได้ใช้ของ SanDisk Cruzer Micro ขนาด 256MB กับ 512MB และ No Name 512MB ซื้อจาก Microware ทำการทดลองกับชุด miniPE หลายรุ่นทั้งของผมทำเอง ของฝรั่ง 4 ชุด และของจีนอีก 3 ชุด ใช้ได้ไม่มีปัญหา……

  • Comments Off

Time

Mp3

Msn status

  • manon2029@hotmail.com is

Chat with Meeh

Donate

    If you find an article useful, then please make a donation.

หมวดหมู่

UserOnline

Counter

  • Visitors today: 23
  • Visitors yesterday: 48
  • Visitors per day: 455
  • Max. visitors per day: 255
  • Total page views: 155,889
  • Page views of this page: 455
  • Currently online: 1
  • Max. online: 23
  • Total visitors: 33,987
  • counterStatistics