我正在开发一个在线应用程序,我有一个php搜索脚本,从数据库中提取所需的信息。我已经设法在脚本中包含一个删除和更新按钮,这样当用户搜索项目时,表格显示为必需数据显示但我不知道如何将按钮绑定到他们的功能。我是新的Php,所以任何帮助表示赞赏。这是我的搜索代码......
<?php
// Get the search variable from URL
$var = @$_GET['s'] ;
$trimmed = trim($var); //trim whitespace from the stored variable
// rows to return
$limit=15;
// check for an empty string and display a message.
if ($trimmed == "")
{
echo "<p>Please enter a search value...</p>";
exit;
}
// check for a search parameter
if (!isset($var))
{
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}
//connect to database
mysql_connect("localhost","root",""); //(host, username, password)
//specify database **
mysql_select_db("archive_sys") or die("Unable to select database"); //select which database we're using
// Build SQL Query
$query = "select * from tbl_archivingdetails where archiveid like \"%$trimmed%\" or buildingid like \"%$trimmed%\" or branchid like \"%$trimmed%\" or study like \"%$trimmed%\" or batchnumber like \"%$trimmed%\" or quantity like \"%$trimmed%\" or archivedate like \"%$trimmed%\" or archivedby like \"%$trimmed%\" or archiveeemail like \"%$trimmed%\" or archiveephone like \"%$trimmed%\" or expecteddestructiondate like \"%$trimmed%\" or currarchholderproj like \"%$trimmed%\" or currexpretdate like \"%$trimmed%\" or returnedby like \"%$trimmed%\" or status like \"%$trimmed%\"";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
// next determine if s has been passed to script, if not use 0
if (empty($s)) {
$s=0;
}
// get results
$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");
// display what the person searched for
echo "<h2>You searched for: "" . $var . ""</h2>";
// begin to show results set
echo "Results: ";
$count = 1 + $s ;
//the begining of a table with a header
echo " <table border=2>";
echo "<tr align=center>";
echo "<th> Check Code </th>";
echo "<th> Archive ID </th>";
echo "<th> Building ID </th>";
echo "<th> Branch ID </th>";
echo "<th> Study </th>";
echo "<th> Batch Number </th>";
echo "<th> Quantity </th>";
echo "<th> Archive Date </th>";
echo "<th> Archived By </th>";
echo "<th> Archivee Email </th>";
echo "<th> Archivee Phone </th>";
echo "<th> Expected Destruction Date </th>";
echo "<th> currArchHolderProj </th>";
echo "<th> Current Exp Return Date </th>";
echo "<th> Returned By </th>";
echo "<th> Status </th>";
//echo "<th> Action </th><tr><td><input type='submit' name='Submit' value='Delete' /> | <input type='submit' name='Submit' value='Update' /> </td></tr>";
echo " </tr>";
// now you can display the results returned
while ($row= mysql_fetch_array($result)) {
$title = $row["archiveid"];
$title1 = $row["buildingid"];
$title2 = $row["branchid"];
$title3 = $row["study"];
$title4 = $row["batchnumber"];
$title5 = $row["quantity"];
$title6 = $row["archivedate"];
$title7 = $row["archivedby"];
$title8 = $row["archiveeemail"];
$title9 = $row["archiveephone"];
$title10= $row["expecteddestructiondate"];
$title11 = $row["currarchholderproj"];
$title12 = $row["currexpretdate"];
$title13 = $row["returnedby"];
$title14 = $row["status"];
echo" <tr>";
echo "<td><input type='checkbox' name='checkbox' value='".$row['archiveid']."' id='checkbox'/> </td> <td>".$title."</td> <td>".$title1."</td><td>".$title2."</td><td>".$title3."</td><td>".$title4."</td><td>".$title5."</td> <td>".$title6."</td><td>".$title7."</td><td>".$title8."</td><td>".$title9."</td><td>".$title10."</td> <td>".$title11."</td><td>".$title12."</td><td>".$title13."</td><td>".$title14."</td>" ;
echo " </tr>";
}
echo "<tr><tr> <td><input type='submit' name='Submit' value='Delete' /></td> | <td><input type='submit' name='Submit' value='Update' /> </td></tr>";
echo " </tr>";
echo " </table>";
//break before paging
echo "<br />";
?>
答案 0 :(得分:1)
您可以这样做,将输入按钮更改为链接并将archiveid附加到链接。
echo "<th> Action </th><tr><td><a href='delete.php?archiveid=" . title . '>Delete</a> | <a href='update.php?archiveid=" . title . '>Update</a> </td></tr>";
现在,这些链接会将您分别发送到delete.php
和update.php
下面的示例是为了简洁而没有安全性,并假设您建立了与db的连接。
//delete.php
$archiveId = $_GET['archiveid'];
//now use your db connection to delete the record according to the archiveid
并在update.php
//update.php
$archiveId = $_GET['archiveid'];
/**
* Use your db connection to retrieve all the data that relates to this archiveid
* Populate a form with all the archive details so you can modify them
* Save the form details to the db when it has been submitted, validated and escaped
* The query should use an UPDATE statement
*/