[請益]在每筆資料前加入checkbox
大家好,我是PHP& MySQL的超級新手。
因為研究的需要,要開發一個可讀取資料庫、讓user輸入資料並作計算的網頁,
所以目前是買書自學中...
現在遇到了一些問題,試了很久卻沒辦法解決,所以想請教版上的各位 m(_ _)m
我想在網頁上秀出資料庫中的一個表格"P",並在每一列資料中加入一個checkbox。
目前我的做法是,新增一個空的欄位"selection"在表格"P"中,
想將checkbox放在"selection"中。圖示如下:
表格P
┌─────┬───┬───┐
│selection │method│result│
├─────┼───┼───┤
│ 空白 │ A │ 10 │
├─────┼───┼───┤
│ 空白 │ B │ 20 │
└─────┴───┴───┘
以下是我的code:
mysql_query("use P");
$sqlstr = "select selection, method, result from P";
$result = mysql_query($sqlstr,$link);
while($field = mysql_fetch_field($result)){
echo "<td width=200>".$field->name. "</td>\n";
}
while ($row = mysql_fetch_row($result)) {
echo"<tr>\n";
echo "<td><input type=checkbox name=chkbox[]
value='".$row['selection']."'></td>";
for($i=0; $i<count($row);$i++){
echo"<td width=200>".$row[$i]."</td>";
}
}
結果變成下面這樣,
┌─────┬───┬───┐
│selection │method│result│
├─────┼───┼───┬───┐
│ checkbox │ │ A │ 10 │
├─────┼───┼───┼───┤
│ checkbox │ │ B │ 20 │
└─────┴───┴───┴───┘
想請教大家,我的code的問題出在哪裡呢?
再次感謝大家看完這麼長的問題 m(_ _)m
也祝大家新年快樂!^^
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.79.191
推
01/05 19:07, , 1F
01/05 19:07, 1F
→
01/05 19:09, , 2F
01/05 19:09, 2F
→
01/05 19:14, , 3F
01/05 19:14, 3F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章
0
18