2013-04-27 41 views
0

我有一個數據庫表與這個模式:PHP文件不會列出在數據庫表中的行

"CREATE TABLE IF NOT EXISTS `call_log` (
`clid` int(6) unsigned NOT NULL AUTO_INCREMENT, 
`medid1` int(6) NOT NULL, 
`medid2` int(6) NOT NULL, 
`patid` int(6) NOT NULL, 
`dcode` varchar(25) NOT NULL, 
`acode` varchar(25) NOT NULL, 
`transp` varchar(10) NOT NULL, 
`facid` int(6) DEFAULT NULL, 
`date1` varchar(45) NOT NULL, 
`time1` varchar(45) NOT NULL, 
`reg-date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 
PRIMARY KEY (`clid`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ; 

正在使用此文件列出表:注意#的PHPconn.php包含日誌在DB

<? 

include("PHPConn.php"); 


mysql_connect ("$host", "$user","$password") or die (mysql_error()); 
mysql_select_db ("$database"); 

echo "<table border=1 >"; 
echo "<tr>"; 
echo "<td><b>Clid</b></td>"; 
echo "<td><b>Medid1</b></td>"; 
echo "<td><b>Medid2</b></td>"; 
echo "<td><b>Patid</b></td>"; 
echo "<td><b>Dcode</b></td>"; 
echo "<td><b>Acode</b></td>"; 
echo "<td><b>Transp</b></td>"; 
echo "<td><b>Facid</b></td>"; 
echo "<td><b>Date1</b></td>"; 
echo "<td><b>Time1</b></td>"; 
echo "<td><b>Reg-date</b></td>"; 
echo "</tr>"; 
$result = mysql_query("SELECT * FROM `call_log`") or trigger_error(mysql_error()); 
while($row = mysql_fetch_array($result)){ 
foreach($row AS $key => $value) { $row[$key] = stripslashes($value); } 
echo "<tr>"; 
echo "<td valign='top'>" . nl2br($row['clid']) . "</td>"; 
echo "<td valign='top'>" . nl2br($row['medid1']) . "</td>"; 
echo "<td valign='top'>" . nl2br($row['medid2']) . "</td>"; 
echo "<td valign='top'>" . nl2br($row['patid']) . "</td>"; 
echo "<td valign='top'>" . nl2br($row['dcode']) . "</td>"; 
echo "<td valign='top'>" . nl2br($row['acode']) . "</td>"; 
echo "<td valign='top'>" . nl2br($row['transp']) . "</td>"; 
echo "<td valign='top'>" . nl2br($row['facid']) . "</td>"; 
echo "<td valign='top'>" . nl2br($row['date1']) . "</td>"; 
echo "<td valign='top'>" . nl2br($row['time1']) . "</td>"; 
echo "<td valign='top'>" . nl2br($row['reg-date']) . "</td>"; 
echo "<td valign='top'><a href=edit.php?id={$row['id']}>Edit</a></td><td><a  href=delete.php?id={$row['id']}>Delete</a></td> "; 
echo "</tr>"; 
} 
echo "</table>"; 
echo "<a href=new.php>New Row</a>"; 
?> 

當我打電話的filel我得到這個錯誤」

"; echo ""; echo "Clid"; echo "Medid1"; echo "Medid2"; echo "Patid"; echo "Dcode"; echo "Acode"; echo "Transp"; echo "Facid"; echo "Date1"; echo "Time1"; echo "Reg-date"; echo ""; $result = mysql_query("SELECT * FROM `call_log`") or trigger_error(mysql_error()); while($row = mysql_fetch_array($result)){ foreach($row AS $key => $value) { $row[$key] = stripslashes($value); } echo ""; echo "" . nl2br($row['clid']) . ""; echo "" . nl2br($row['medid1']) . ""; echo "" . nl2br($row['medid2']) . ""; echo "" . nl2br($row['patid']) . ""; echo "" . nl2br($row['dcode']) . ""; echo "" . nl2br($row['acode']) . ""; echo "" . nl2br($row['transp']) . ""; echo "" . nl2br($row['facid']) . ""; echo "" . nl2br($row['date1']) . ""; echo "" . nl2br($row['time1']) . ""; echo "" . nl2br($row['reg-date']) . ""; echo "EditDelete "; echo ""; } echo ""; echo "New Row"; ?> 

我可以將數據表通過表單機智添加信息豪特問題。

任何想法?

謝謝

+1

最新錯誤? – Aris 2013-04-27 13:04:44

+0

mysql_query已被棄用請使用mysqli或PDO – underscore 2013-04-27 13:06:44

+0

我已添加Niels修訂現在錯誤是類似拉差錯,除了表格框架顯示。我想要做的就是列出表格中的所有行。謝謝你們所有的幫助 – user2326872 2013-04-27 13:32:46

回答

0

這裏的一個明顯的問題,你居然不要有所謂的「身份證」數組中的一個項目

echo "<td valign='top'><a href=edit.php?id={$row['id']}>Edit</a> 

如果不是這種

echo "<td valign='top'><a href=edit.php?id={$row['clid']}>Edit</a> 

也就是爲什麼打擾foreach循環,爲什麼不只是這樣做

echo「」。 nl2br(stripslashes($ row ['clid']))。 「」;

+0

我解決了這個問題,我不明白爲什麼,但我發現了<?標籤來啓動PHP腳本必須以<?PHP而不是<?開頭。爲這個文件。我改變了原來的代碼,它工作正常 – user2326872 2013-04-27 16:13:53

+0

@裏格斯的'ID'標識在SQL中的行。 'clid'標識了我們人類的行。我可能是錯的,但那是我如何忍受它。我所做的只是改變<?到<?PHP工作正常。 – user2326872 2013-04-27 16:18:26

相關問題