我想允许用户通过移动它们向上或向下重新排序MySQL表行。我有2页让这个工作。它不工作,我真的不知道该从哪里出发。我收到此错误:Fatal error: Call to undefined method Database::GetAll() in /home/www/thetotempole.ca/phptester/moveupdown.php on line 35
这里是我的PHP:PHP数据库类不工作
moveupdown.php
<?php
class Database extends mysqli {
function __construct() {
parent::__construct("","","","");
if (mysqli_connect_errno()) {
throw new Exception(mysqli_connect_error(),
mysqli_connect_errno());
}
}
}
include 'connect.php';
$db = new Database();
if(isset($_POST['do'])){
extract($_POST);
//determine what direction in relation to $_POST['position']
$otherpos = $do=='⇑'? $position-1:$position+1;
//get the two ID that should change order place
$sql = "SELECT id FROM employees WHERE emp_id=$position";
$posid = $db->GetRow($sql);
$sql = "SELECT id FROM employees WHERE emp_id=$otherpos";
$other = $db->GetRow($sql);
//change place for those two
$sql = "UPDATE employees SET position=$otherpos WHERE id=$posid->id";
$db->Query($sql);
$sql = "UPDATE forums SET position=$position WHERE id=$other->id";
$db->Query($sql);
}else{
// make sure all forums positions are numbered 1,2,3,4,5 etc.
$sql = "SELECT id FROM employee ORDER BY position";
$forums = $db->GetAll($sql);
foreach($forums AS $f){
$items[] = $f->id;
}
foreach($items AS $k=>$id){
$k++;
$sql = "UPDATE employee SET position=$k WHERE id=$id";
$db->Query($sql);
}
}
//get the number of forums to display
$sql = "SELECT COUNT(*) AS max FROM employee";
$pos = $db->GetRow($sql);
//get them by order of position
$sql = "SELECT * FROM employee ORDER BY position";
$forums = $db->GetAll($sql);
//display with up/down arrows for each
//except first forum has only down-arrow
//and last forum has only up-arrow
$out ='<table>'."\n";
foreach($forums as $f){
$out .= '<form method="post">';
$out .= '<input type="hidden" name="position" value="'.$f->position.'">'."\n".'<tr>';
if($f->position != 1)
$out .= '<td><input type="submit" name="do" value="⇑"></td>'; //up
else $out .= '<td></td>';
if($f->position != $pos->max)
$out .= '<td><input type="submit" name="do" value="⇓"></td>'; //down
else $out .= '<td></td>';
$out .= '<td>'.$f->name.'</td></tr>'."\n";
$out .= '</form>'."\n";
}
$out .= '</table>';
echo $out;
?>
connect.php
<?
//the example of MySQL database connection
//connect.php
$continued = mysql_connect("","","","");
if ($continued) {
echo ("Connection is succeed");
} else {
echo ("Connection is fail");
}
?>
和'不working'手段? –
致命错误:调用未定义的方法Database :: GetAll()在/home/www/thetotempole.ca/phptester/moveupdown.php在第35行是我的错误。我不确定这意味着什么。 – Kelsey
好的,我们在哪里可以在你的类或'mysqli'中定义一个'GetAll()'方法? –