switch order of two records in a table

Posted: April 16th, 2008 | Author: admin | Filed under: Developers | No Comments »

When in need to change the order of a list use a field to store the order as an int:
Change the order of the records by switching the order value between consecutive elements.

<?php
switch ($action){
    case 'orderdown':
    case 'orderup':{
        //get all list and retain two elements: if moveup operation then I keep prev and current  
        //otherwise I keep current and next
        $rec_list = $this->getChildren($record->id_parent);//all records on this level
        $switch = array();
        for($i = 0; $i < count($rec_list) ; $i++){
            if($rec_list[$i]['id'] == $record['id']){
                if('orderup' == $what && $i != 0){    //not first
                    $switch[$rec_list[$i-1]['id']] = $rec_list[$i]['corder'];
                    $switch[$rec_list[$i]['id']] = $rec_list[$i-1]['corder'];
                    break;
                }elseif('orderdown' == $what && $i != (count($rec_list)-1)){    //not last
                    $switch[$rec_list[$i+1]['id']] = $rec_list[$i]['corder'];
                    $switch[$rec_list[$i]['id']] = $rec_list[$i+1]['corder'];
                    break;
                }
            }
        }

        //valid elements found. Switch them
        if(count($switch) > 0){
            foreach ($switch as $id=>$corder) {
                $sql = "UPDATE page SET corder=$corder WHERE$id";
                $result = mysql_query($sql) or die("SQL ERROR " . mysql_error() . " [$sql] on " . __FILE__ . " at line " . __LINE__);
            }
        }
    }break;
}
?>
 


Centered popup window

Posted: April 16th, 2008 | Author: admin | Filed under: Developers, Javascript | No Comments »

<SCRIPT TYPE="text/javascript">
<!–
function popUp(theURL, myWidth, myHeight) {
    var winName = 'feedback';
    var features='toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0';
    //var myWidth = 290;
    //var myHeight = 360;
    var isCenter = 'true';
    if(window.screen)
        if(isCenter && isCenter=="true"){  
            var myLeft = (screen.width-myWidth)/2;  
            var myTop = (screen.height-myHeight)/2;  
            features+=(features!=")?',':";  
            features+=',left='+myLeft+',top='+myTop;
        }
    var handle = window.open(theURL,winName,features+((features!=")?',':")+'width='+myWidth+',height='+myHeight);
    handle.opener = window;  handle.focus(); return handle;
}
//–></SCRIPT>
 


Contact us

Posted: March 22nd, 2008 | Author: admin | Filed under: General | No Comments »
Highlighted fields are required.
Your Name:
Your Email:
8 + 1 =
Your Website:
Your Subject:
Your Message:

Payment Options

Posted: March 22nd, 2008 | Author: admin | Filed under: General | No Comments »

Payment Options:

Pay for 1 Article $10
[paybutton]1 Article post|1|10|||[/paybutton]


adnetworks

Posted: March 22nd, 2008 | Author: admin | Filed under: General | No Comments »

Comming soon


TAI : PHP - Think About It

Posted: March 7th, 2008 | Author: admin | Filed under: General | No Comments »

Welcome to Tai : PHP - Think About It

PHP Resources