class SortableExample {
var $conn;
var $user = 'root';
var $pass = '';
var $dbname = 'test';
var $host = 'localhost';
function SortableExample() {
$this->conn = mysql_connect($this->host, $this->user, $this->pass);
mysql_select_db($this->dbname,$this->conn);
}
function getList() {
$sql = "SELECT * FROM categories ORDER BY orderid";
$recordSet = mysql_query($sql,$this->conn);
$results = array();
while($row = mysql_fetch_assoc($recordSet)) {
$results[] = $row;
}
return $results;
}
function updateList($orderArray) {
$orderid = 1;
foreach($orderArray as $catid) {
$catid = (int) $catid;
$sql = "UPDATE categories SET orderid={$orderid} WHERE catid={$catid}";
$recordSet = mysql_query($sql,$this->conn);
$orderid++;
}
}
}
?>
|