次のDBとPHPがあります。これを CodeIgniter で MVC に変換しようとしていますが、これまでに得たものは次のとおりで、機能していません。誰かが私が間違っていることを指摘できれば、感謝します。
私のSQLとPHP
データベース
CREATE TABLE seats
(
rowId varchar(1) not null,
columnId int not null,
status int,
updatedby varchar(10),
PRIMARY KEY (rowId,columnId)
);
CREATE TABLE userauth (
rowID TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
commonname VARCHAR(35) NOT NULL,
username VARCHAR(8) NOT NULL,
pswd VARCHAR(32) NOT NULL,
PRIMARY KEY(rowID)
);
insert into seats values (‘A’, 1, 0, ‘’);
insert into seats values (‘A’, 2, 0, ‘’);
insert into seats values (‘B’, 1, 0, ‘’);
insert into seats values (‘B’, 2, 0, ‘’);
insert into seats values (‘C’, 1, 0, ‘’);
insert into seats values (‘C’, 2, 0, ‘’);
insert into seats values (‘D’, 1, 0, ‘’);
insert into seats values (‘D’, 2, 0, ‘’);
menu.php (元の PHP と動作)
<?php
$linkID = @ mysql_connect(“localhost”, “tickets”, “tickets”) or die(“Could not connect to MySQL server”);
@ mysql_select_db(“tickets”) or die(“Could not select database”);
$query = “SELECT * from seats order by rowId, columnId desc”;
$result = mysql_query($query);
$prevRowId = null;
$seatColor = null;
$tableRow = false;
//echo $result;
echo “<table width=‘100%’ border=‘0’ cellpadding=‘3’ cellspacing=‘3’>”;
while (list($rowId, $columnId, $status, $updatedby) = mysql_fetch_row($result))
{
if ($prevRowId != $rowId) {
if ($rowId != ‘A’) {
echo “</tr></table></td>”;
echo “\n</tr>”;
}
$prevRowId = $rowId;
echo “\n<tr><td align=‘center’><table border=‘1’ cellpadding=‘8’ cellspacing=‘8’> <tr>”;
} else {
$tableRow = false;
}
if ($status == 0) {
$seatColor = “lightgreen”;
} else if ($status == 1 && $updatedby == ‘user1’) {
$seatColor = “FFCC99”;
} else if ($status == 1 && $updatedby == ‘user2’) {
$seatColor = “FFCCFF”;
} else if ($status == 2 && $updatedby == ‘user1’) {
$seatColor = “FF9999”;
} else if ($status == 2 && $updatedby == ‘user2’) {
$seatColor = “CC66FF”;
} else {
$seatColor = “red”;
}
echo “\n<td bgcolor=’$seatColor’ align=‘center’>”;
echo “$rowId$columnId”;
if ($status == 0 || ($status == 1 && $updatedby == $_SERVER[‘PHP_AUTH_USER’])) {
echo “<input type=‘checkbox’ name=‘seats[]’ value=’$rowId$columnId’></checkbox>”;
}
echo “</td>”;
if (($rowId == ‘A’ && $columnId == 7)
|| ($rowId == ‘B’ && $columnId == 9)
|| ($rowId == ‘C’ && $columnId == 9)
|| ($rowId == ‘D’ && $columnId == 10)
) {
// This fragment is for adding a blank cell which represent the “center aisle”
echo “<td> </td>”;
}
}
echo “</tr></table></td>”;
echo “</tr>”;
echo “</table>”;
mysql_close();
?>
評判が悪いので画像を投稿できないので、この元の PHP の出力/スクリーンショットを投稿します。
これまでのところ私のMVCは機能していません
CodeIgniter モデル
<?php
class Bus_model extends CI_Model {
public function __construct()
{
//$this->load->database();
}
function get() {
$this->load->database();
$query=$this->db->query(‘SELECT * from seats order by rowId, columnId desc’);
return $query->result();
}
}
>
コントローラ
<?php
class Bus_type extends Controller
{
function Bus_agent()
{
parent::Controller();
}
function Bus_fun()
{
$this->load->model(‘busmodel’);
$data[‘query’] = $this->busmodel->get();
$this -> load ->view(‘view’);
}
}
意見
<?PHP
$prevRowId = null;
$seatColor = null;
$tableRow = false;
echo “<table width=‘100%’ border=‘0’ cellpadding=‘3’ cellspacing=‘3’>”;
while (list($rowId, $columnId, $status, $updatedby) = mysql_fetch_row($result))
{
if ($prevRowId != $rowId) {
if ($rowId != ‘A’) {
echo “</tr></table></td>”;
echo “\n</tr>”;
}
$prevRowId = $rowId;
echo “\n<tr><td align=‘center’><table border=‘1’ cellpadding=‘8’ cellspacing=‘8’><tr>”;
} else {
$tableRow = false;
}
if ($status == 0) {
$seatColor = “lightgreen”;
} else if ($status == 1 && $updatedby == ‘user1’) {
$seatColor = “FFCC99”;
} else if ($status == 1 && $updatedby == ‘user2’) {
$seatColor = “FFCCFF”;
} else if ($status == 2 && $updatedby == ‘user1’) {
$seatColor = “FF9999”;
} else if ($status == 2 && $updatedby == ‘user2’) {
$seatColor = “CC66FF”;
} else {
$seatColor = “red”;
}
echo “\n<td bgcolor=’$seatColor’ align=‘center’>”;
echo “$rowId$columnId”;
if ($status == 0 || ($status == 1)) {
echo “<input type=‘checkbox’ name=‘seats[]’ value=’$rowId$columnId’></checkbox>”;
}
echo “</td>”;
if (($rowId == ‘A’ && $columnId == 7)
|| ($rowId == ‘B’ && $columnId == 9)
|| ($rowId == ‘C’ && $columnId == 9)
) {
}
}
echo “</tr></table></td>”;
echo “</tr>”;
echo “</table>”;
>
エラー
Error
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: result
Filename: views/view.php
Line Number: 6
—
A PHP Error was encountered
Severity: Warning
Message: mysql_fetch_row() expects parameter 1 to be resource, null given
Filename: views/view.php
Line Number: 6