[英]PHP + MySQL - Autocomplete from database not getting data from table
[英]PHP getting data from HTML table to update MySQL database
我有一個小問題,我需要從這個HTML表中讀取數據,問題是我不知道要擁有多少表行,因為我將數據從MySQL select中放入其中,所以我真正想要的是select之后,以在HTML表中添加一些特定的數據:
<td><input type="text" size="5px"></td>
然后單擊按鈕以從所有新表行輸入中讀取數據。
<table style="display:inline">
<tr>
<td></td>
<th>Home team</th>
<td></td>
<td></td>
<td></td>
<th>Away team</th>
</tr>
<?php
$i=0;
while ($i < $num) {
$Tim1=mysql_result($result,$i,"HomeTeamID");
$Tim1Name=mysql_result($result,$i,"HomeTeam");
$Tim2=mysql_result($result,$i,"AwayTeamID");
$Tim2Name=mysql_result($result,$i,"AwayTeam");
$rez=mysql_result($result,$i,"MatchID");
?>
<tr>
<td class="ID" id="<?php echo $rez;?>"><input value="<?php echo $rez;?>"
name="<?php echo $rez;?>" type="hidden" style="display: none">
</td>
<td><label style="padding-right:10px" ><?php echo($Tim1Name); ?></label></td>
<td><input type="text" size="5px"></td>
<td><label>:</label></td>
<td><input type="text" size="5px"></td>
<td><label style="padding-left:10px"><?php echo($Tim2Name); ?></label></td>
</tr>
<?php
$i++;
}
?>
<tr align="right" style="padding-top:5px">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><input type="submit" value="Insert" name="Insert"></td>
</tr>
</table>
如果您不明白我的問題,請問您想要什么,我會回答。
嘗試使用以下內容
首先在您的頭部添加一個jQuery庫
然后建立一個像這樣的功能
$(document).ready(function(){
$('.insert').click(function({
$('.testValues').each(function(){
var Values=$(this).attr('title');
$(this).val(Values);
$(this).attr('title','');
});
});
});
並更改您的HTML以影響上述代碼,如下所示
<table style="display:inline">
<tr>
<td></td>
<th>Home team</th>
<td></td>
<td></td>
<td></td>
<th>Away team</th>
</tr>
<?php
$i=0;
while ($i < $num) {
$Tim1=mysql_result($result,$i,"HomeTeamID");
$Tim1Name=mysql_result($result,$i,"HomeTeam");
$Tim2=mysql_result($result,$i,"AwayTeamID");
$Tim2Name=mysql_result($result,$i,"AwayTeam");
$rez=mysql_result($result,$i,"MatchID");
?>
<tr>
<td class="ID" id="<?php echo $rez;?>"><input value="<?php echo $rez;?>"
name="<?php echo $rez;?>" type="hidden" style="display: none">
</td>
<td><label style="padding-right:10px" ><?php echo($Tim1Name); ?></label></td>
<td><input type="text" size="5px" class="testvalues" title="<?php echo($Tim1); ?>"></td>
<td><label>:</label></td>
<td><input type="text" size="5px" class="testvalues" title="<?php echo($Tim2); ?>"></td>
<td><label style="padding-left:10px"><?php echo($Tim2Name); ?></label></td>
</tr>
<?php
$i++;
}
?>
<tr align="right" style="padding-top:5px">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><input type="button" value="Insert" name="Insert" class="insert"></td>
</tr>
</table>
由於我沒有調試代碼,因此請檢查您放置該代碼的錯誤控制台,不要忘記添加jquery庫
您可以使用JQuery遍歷表並提取值。 我不明白從表中再次讀取數據的目的是什么。但是嘗試下面的代碼:
假設您有一個表格ID,
<table id='teams_table'>
然后使用此JQuery腳本遍歷表行;
var cells = 6; //number of collumns
var cell_text = '';
$('tr',$('#teams_table')).each(function(){
for(var i = 0 ; i < cells ; i++){
cell_text = $(this).find('td').eq(i).text();
//do what ever you want with cell_text
}
});
如果您需要更多幫助,請更詳細地描述您的方案。
希望這可以幫助! :-)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.