PHP gevorderde |
|
Beste allemaal,
Ik ben een ajax cms aan het maken. ik doe database requests via php. ik zie in firebug dat deze interactie langzaam gaat.
ik heb een zogenaamd service script die zorgt voor de interactie tussen javascript en php classes:
<?PHP
if($_POST['klass'] == 'core')
{
if($_POST['methode'] == 'getLogin')
{
print $json->encode($cCore->getLogin($_POST['username'], $_POST['password']));
}
elseif($_POST['methode'] == 'getMenu')
{
print $json->encode($cCore->getMenu());
}
elseif($_POST['methode'] == 'getAllFromFolder')
{
print $json->encode($cCore->getAllFromFolder($_POST['table'], $_POST['folderid']));
}
elseif($_POST['methode'] == 'getInterfaceByTable')
{
print $json->encode($cCore->getInterfaceWithValue($_POST['table'], $_POST['id']));
}
elseif($_POST['methode'] == 'setItem')
{
print $json->encode($cCore->setItem($_POST['table'], $_POST['id'], $_POST, $_POST['folder']));
}
}
?>
<?PHP if($_POST['klass'] == 'core') { if($_POST['methode'] == 'getLogin') { print $json->encode($cCore->getLogin($_POST['username'], $_POST['password'])); } elseif($_POST['methode'] == 'getMenu') { print $json->encode($cCore->getMenu()); } elseif($_POST['methode'] == 'getAllFromFolder') { print $json->encode($cCore->getAllFromFolder($_POST['table'], $_POST['folderid'])); } elseif($_POST['methode'] == 'getInterfaceByTable') { print $json->encode($cCore->getInterfaceWithValue($_POST['table'], $_POST['id'])); } elseif($_POST['methode'] == 'setItem') { print $json->encode($cCore->setItem($_POST['table'], $_POST['id'], $_POST, $_POST['folder'])); } } ?>
de code in de classe:
<?PHP
function getInterfaceByTable($table)
{
$sQuery = "SELECT
*
FROM
interface
WHERE
tablename = '".mysql_real_escape_string($table)."'
ORDER BY
sequencenumber
";
$rs = $this->conn->GetAll($sQuery);
return $rs;
}
function getItemById($table, $id, $column)
{
$sQuery = "SELECT
$column
FROM
$table
WHERE
id = '".intval($id)."'
";
$rs = $this->conn->GetOne($sQuery);
if (gettype($rs) == 'string')
{
$rs = htmlentities($rs);
}
return $rs;
}
function getInterfaceWithValue($table, $id)
{
$interface = $this->getInterfaceByTable($table);
for ($i = 0; $i < count($interface); $i++)
{
$interface[$i]['value'] = $this->getItemById($table, $id, $interface[$i]['column']);
}
return $interface;
}
?>
<?PHP function getInterfaceByTable($table) { $sQuery = "SELECT * FROM interface WHERE ORDER BY sequencenumber "; $rs = $this->conn->GetAll($sQuery); return $rs; } function getItemById($table, $id, $column) { $sQuery = "SELECT $column FROM $table WHERE "; $rs = $this->conn->GetOne($sQuery); { } return $rs; } function getInterfaceWithValue($table, $id) { $interface = $this->getInterfaceByTable($table); for ($i = 0; $i < count($interface); $i++) { $interface[$i]['value'] = $this->getItemById($table, $id, $interface[$i]['column']); } return $interface; } ?>
Misschien hebben jullie tips/ voorbeelden of aanpassingen waarmee de interactie sneller zal verlopen.
Misschien kan iemand de drie functies aanpassen zodat het sneller werkt.
Groeten,
Roy
|