[請益]在每筆資料前加入checkbox

看板PHP作者 (決心)時間16年前 (2010/01/05 17:20), 編輯推噓1(102)
留言3則, 1人參與, 最新討論串1/1
大家好,我是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
field name沒有tr
01/05 19:07, 1F

01/05 19:09, , 2F
後面也少 </tr>
01/05 19:09, 2F

01/05 19:14, , 3F
這種問題請打開原始碼 從HTML層面找問題 跟PHP其實無關
01/05 19:14, 3F
文章代碼(AID): #1BGmH8GQ (PHP)
文章代碼(AID): #1BGmH8GQ (PHP)