I found some sample code I would like to use but it said I might need to change it for php4. I ran it and sure enough it does not work. What would I need to change for this to work?
<?
class SortableExample {
protected $conn;
protected $user = 'test';
protected $pass = 'test';
protected $dbname = 'scriptaculous';
protected $host = 'localhost';
public function __construct() {
$this->conn = mysql_connect($this->host, $this->user, $this->pass);
mysql_select_db($this->dbname,$this->conn);
}
public 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;
}
public 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++;
}
}
}
?>
Thanks,
TravisSomething like this:
<?
class SortableExample {
var $conn;
var $user = 'test';
var $pass = 'test';
var $dbname = 'scriptaculous';
var $host = 'localhost';
function __construct() {
$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++;
}
}
}
?>
Note that you must manually call __construct as this is not automatically done in PHP4.
So in PHP5 you would do:
$mySortable = new SortableExample();
in PHP4:
$mySortable = new SortableExample();
$mySortable->__construct();
Optionally you can change the __construct name to your classname to achieve the same "effect" as in PHP5.
function __construct becomes function SortableExampleBetter yet, change the name of the constructor to the same as the class:
"A function becomes a constructor, when it has the same name as the class. If a class has no constructor, the constructor of the base class will be called, if it exists."
So just change function __construct to function SortableExample
Sorry Azala, did not see you had already said that.
<?
class SortableExample {
protected $conn;
protected $user = 'test';
protected $pass = 'test';
protected $dbname = 'scriptaculous';
protected $host = 'localhost';
public function __construct() {
$this->conn = mysql_connect($this->host, $this->user, $this->pass);
mysql_select_db($this->dbname,$this->conn);
}
public 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;
}
public 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++;
}
}
}
?>
Thanks,
TravisSomething like this:
<?
class SortableExample {
var $conn;
var $user = 'test';
var $pass = 'test';
var $dbname = 'scriptaculous';
var $host = 'localhost';
function __construct() {
$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++;
}
}
}
?>
Note that you must manually call __construct as this is not automatically done in PHP4.
So in PHP5 you would do:
$mySortable = new SortableExample();
in PHP4:
$mySortable = new SortableExample();
$mySortable->__construct();
Optionally you can change the __construct name to your classname to achieve the same "effect" as in PHP5.
function __construct becomes function SortableExampleBetter yet, change the name of the constructor to the same as the class:
"A function becomes a constructor, when it has the same name as the class. If a class has no constructor, the constructor of the base class will be called, if it exists."
So just change function __construct to function SortableExample
Sorry Azala, did not see you had already said that.