2011-02-14 62 views
1

我想从我的MySQL数据库中检索数据并将其显示为表格(我不介意任何样式,但首选为表格)。然后数据应该显示一个单选按钮或一个正常的按钮,更新该特定行并将该行中的单个列更改为活动(状态生成活动)。从MySQL中检索数据并进行相应更新

我已经开始了它,但我仍然有添加单选按钮或按钮的问题。然后我想到了将信息显示在表格内的表格中。当这个人选择那个单选按钮并按提交时,这个表单将有每个单选按钮。数据应该在MySQL数据库中更新。

有人可以指导我吗?我有点困惑。我很困惑,因为我必须添加一个表单,并以这种形式添加一个表格,所有这些东西都应该放在一个php文件中。

+0

刚才出了什么问题`

..
`?另外,我建议使用复选框而不是收音机。复选框有一个值参数,可以用来保存行的ID – 2011-02-14 05:59:47

回答

-1

继续尝试这样的事情。并告诉我是否奏效:

<p><b>your page name</b></p> 
<form name="formpost" id="formpost" action="formpost.php" method="POST"> 
<table border="2" cellpadding="5" cellspacing="1" style="border-collapse: collapse" bordercolor="#999999" width="800"> 
    <tr> 
    <td><b>Sno.</b></td> 
    <td><b>Field name1</b></td> 
    <td><b>Field name2</b></td> 
    <td><b>Field name3</b></td> 
    <td><b>Field name4</b></td> 
    <td><b>Field name5</b></td> 
    <td><b>Field name6</b></td> 
    <td><b>Field name7</b></td> 
    </tr> 

    <? 
    $sorting=""; 
    if($orderby!="" && $direction!="") $sorting=" ORDER BY $orderby $direction";  
    $query = "SELECT * FROM table WHERE something = 'something' $sorting"; 
    $result = mysql_query($query); 
    ?> 
    <tr> 
    <? 
    $i=0; 
    while ($row = mysql_fetch_array($result)) 
    { 
    $i++; 

    ?> 
    <td><input type="checkbox" name="list[<?echo $i?>]" id="list[]" value="<?echo $row['some_primary_field_id']?>"><?echo $i?></td> 
    <td><?echo $row['Field1']?></td> 
    <td><?echo $row['Field2']?></td> 
    <td><?echo $row['Field3']?></td>  
    <td><?echo $row['Field4']?></td> 
    <td><?echo $row['Field5']?></td> 
    <td><?echo $row['Field6']?></td> 
    <td><p align="center"> 

    <? 
    echo "<input title='button' name='change this row' value='Some Button' type='button' onClick=\"if(confirm('Press OK to change status to confirm')) {document.getElementById('someid').value='".$row['Field1']."';document.getElementById('formpost').submit();}\"/>"; 
    ?> 
    </td> 
    </tr> 
<input type='hidden' name="hiddenlist[<?echo $i?>]" id="hiddenlist[]" value="<?echo "some boundry condition ".$row['Field2']?>"> 

<? 
} //end of while 
?> 
</table> 
</form> 
+2

OMG,SQL注入! – 2011-02-14 06:21:53

0

formpost.php页面上,你可以处理你从以前的页面接到单子阵列做这样的事情:

<? 
$list = $_POST['list']; 

foreach ($list as $key => $list_php) 
{ 
$query1 = "SELECT * FROM `stu_entry` WHERE `stu_entry`.`Student_No` = '$list_php' AND `stu_entry`.`Out_Time` = '0000-00-00 00:00:00'"; 
$result1 = mysql_query($query1); 
$row1=mysql_fetch_array($result1); 


//whatever you want to do 

} 
?> 

我忘了告诉你在上一篇文章中。在表单页面中,假设您有100行,并带有100个复选框。手动检查或取消全部检查将是令人讨厌的。作为替代,你可以在页面的末尾添加一个小脚本来处理选中/取消选中为您办理:

<script> 
function checkAll(field) 
{ 
for (i = 0; i < field.length; i++) 
    field[i].checked = true ; 
} 

function uncheckAll(field) 
{ 
for (i = 0; i < field.length; i++) 
    field[i].checked = false ; 
} 

function countChecks(form){ 
var t=0; 
var c=form['list[]']; 
for(var i=0;i<c.length;i++){ 
c[i].checked?t++:null; 
} 
return t; 
} 

</script> 

<input type="button" name="CheckAll" value="Check All" 
onClick="checkAll(document.formpost['list[]'])"> 
<input type="button" name="UnCheckAll" value="Uncheck All" 
onClick="uncheckAll(document.formpost['list[]'])"> 

<i>with selected: </i> 

<select name="submit_mult" id="submit_mult"> 
    <option value="todo1">Action 1 </option> 
    <option value="todo2">Action 2 </option> 
    </select> 
<input type="button" name="go" value="Go" onClick='if(countChecks(this.form)>0) {if(confirm("are you sure you want to \""+document.getElementById("submit_mult").options[document.getElementById("submit_mult").selectedIndex].text+" "+countChecks(this.form)+" items selected"+"\"")) {document.getElementById("referenceToSomeHiddenElement").value=document.getElementById("submit_mult").options[document.getElementById("submit_mult").selectedIndex].value;document.getElementById("formpost").submit();}} else alert("you have not selected any item!!")' > 

告诉我,如果你需要更多这方面的帮助。

0

我首先指定一个MySQL命令,它返回给我一个数组。我使用while语句对数组中的每个项目执行一些操作。数组填充字段名称和字段内容。

$mysql = mysql_query("SELECT * FROM table"); 
while ($array = mysql_fetch_array($mysql)) 
{ 
    $output .= '<form>Row: ' . $array['fieldname'] . ' <input type="button" value="Update" /></form>'; 
} 

这将提取表中的所有行,并为每个结果的变量$输出添加一个表单。我不确定你想如何更新你的数据库,所以你必须研究它。您可以使用GET和POST方法。

相关问题