1

好的,所以我有一个使用 php 基于 mySQL 表构建表的页面:

表格.php

$page .='<form method="POST" action="processing.php">';
$page .= "<table> \n";
$page .= "<tr>\n";  
$page .= "<th>ID</th> \n <th>First Name</th> \n <th>Last Name</th> \n <th>PhoneNumber</th> \n <th>Email</th> \n";

//Loops through each contact, displaying information in a table according to login status
$sql2="SELECT cID, firstName, lastName, phoneNum, email FROM Contact WHERE oID=".$_GET['orgID'];
$result2=mysql_query($sql2, $connection) or die($sql1);
while($row2 = mysql_fetch_object($result2))
{
    $page .= "<tr>\n";
    $page .= "<td>".$row2->cID."</td>\n";
    $page .= "<td>".$row2->firstName."</td>\n";
    $page .= "<td>".$row2->lastName."</td>\n";
    $page .= "<td>".$row2->phoneNum."</td>\n";
    $page .= "<td>".$row2->email."</td>\n";
    //Will only display these buttons if logged in
    $page .= '<td><input type="checkbox" name="checkedItem[]" value="'.$row2->cID.'"></input></td>'."\n";
    $page .= "<td>".makeLink("addEditContact.php?cID=".$row2->cID, "Edit")."</td>\n";
    $page .="</tr>";
}


$page .= "</table>";
//Two buttons sending to processing.php to decide what to do with selected values from there
$page .= '<input name="addToContacts" type="submit" value="Add Selected Contacts To Contact List" />'."\n" ;
$page .= '<input name="deleteContacts" type="submit" value="Delete Selected Contacts" />'."\n";
$page .= "</form>\n";
mysql_close($connection);

因此,基于复选框,我可以选择将联系人添加到另一个表,或从该表中删除联系人,方法是首先将此表单的信息发送到 processing.php 页面,该页面决定单击哪个按钮并重定向到正确的 php 脚本:

处理.php:

if(!empty($_POST['checkedItem']))
{
    //Because addToContacts and deleteContacts take in GET instead of POST for convinience, it needs to take all of checkItems and implode it
    $var=$_POST['checkedItem'];
    ksort($var);
    $joinedString= implode(',',$var);
    //Since there are two buttons in orgDetail, it checks for which was pushed and sends it to the correct page
    if(!empty($_POST['addToContacts']))
    {
        header('Location: addToContacts.php?cID='.$joinedString);
    }

    else if($_POST['deleteContacts'])
    {
        header('Location: deleteContacts.php?cID='.$joinedString);
    }
}
else
{
    //Error for not selecting any items
    $page .= makeP("You have not checked off any items. Please click ".makeLink( $currentPage, "here")." to return to previous page");
}

而且因为我现在只对删除联系人案例感兴趣。这是 deleteContacts.php

$explodedString=explode(',',$_GET['cID']);


    foreach($explodedString as $eString)
    {
        $sql1="DELETE FROM Contact WHERE cID='".$eString."'";
        mysql_query($sql1, $connection) or die($sql1);
    }
header('Location: '. $currentPage);

所以从这里开始变得复杂。当我希望页面同步工作时,这很好用。它在 php 脚本周围反弹,一切都很好。如果我想使用 jquery 直接从 tables.php 中删除怎么办。所以我的意思是,它将运行 mysql 查询以从实际数据库中删除条目,并且在它更新 table.php 中的表视图以反映该更改之后;全部异步完成?

(请忽略所有 sql 查询都不是转义字符串的事实,我意识到这一点,我将不得不稍后修复)

提前致谢。

4

1 回答 1

0

如果您需要在没有 javascript 的情况下支持该表,请先使其正常工作

在不启用 Javascript 的情况下使表格保持最新的唯一方法是刷新页面并在每次加载时重新绘制表格。

于 2014-02-03T18:38:02.557 回答