小女子求教,如何在点击php网页里table中的某记录时,删除数据库中相应记录?
比如php编写的网页中table类似于:
序号 姓名 性别 删除 编辑
1 张三 男 删除 编辑
2 李四 女 删除 编辑
其中,序号、姓名、性别等都是直接从数据库读出来的。
如何做到,在点击序号为1的“删除”时,从数据库中删除序号为1的整条记录?
(删除是href格式的,链接到处理页面。)
想通过点击“删除”时获取序号,然后通过表单POST传递给处理页面,
由处理页面对数据库进行操作。
但是不知道如何获取这个序号啊~~~~~~~~~~
谢谢大神啦
------解决思路----------------------
这个得用js获取序号然后赋值到表单当中一个字段里通过post进行操作。
如果就是一个删除完全可以通过Ajax来实现这样就避免提交表单时整个页面都刷新
------解决思路----------------------
找不到row?
序号 姓名 性别 删除 编辑
1 张三 男 删除 编辑
2 李四 女 删除 编辑
那這些記錄你是如何讀出的?讀出的代碼發來看看
------解决思路----------------------
<br /><?php<br />// 执行 SQL<br />$sql="select * from users ";<br />// 执行查询<br />$result = mysql_query($sql);<br /><br />// 结果<br />// 参见 mysql_result(), mysql_fetch_array(), mysql_fetch_row() 等。<br />while ($row = mysql_fetch_assoc($result)) {<br /> echo $row['序号'];<br /> echo $row['姓名'];<br /> echo $row['性别'];<br />echo '<a href ="delete.php?id = '.$row['序号']. ' " >删除</a>';<br />}<br /><br />// 释放关联结果集的资源<br />// 在脚本结束的时候会自动进行<br />mysql_free_result($result);<br />?><br /><br />
把数据库的字段替换一下,里面的 序号 姓名 性别
------解决思路----------------------
正好前段时间刚写了一个,给你参考下
<table width="100%"><br /> <tr><td>标题</td><td>栏目</td><td>创建时间</td><td>置顶</td><td>删除</td></tr><br /><br /> <br /><br /> <br /> <br /> <?php <br /> <br /> <br /> <br /> /*输出*/ <br /> $sql = "select count(*) from blog";<br /> $rs = $con->query($sql);<br /> $row = $rs->fetch_array();<br /> $num = $row[0];//总文章条数<br /><br /> $recordnum = 8; //每页显示文章数<br /> $pages = ceil($num/$recordnum);// 总页数<br /><br /> if ($_GET['id'])<br /> {<br /><br /> if($_GET['id']==1){<br /> $current = 1;//当前页<br /> $pre = 1; //前一页 <br /> $next = 2; //后一页<br /> }else if($_GET['id']>1){<br /> $pre = $_GET['id']-1;<br /> $current =$_GET['id']; <br /> $next =$_GET['id']+1; <br /> }<br /> } else{<br /> //空值<br /> $current = 1;<br /> $pre = 1;<br /> $next = 2;<br /> }<br /> <br /><br /><br /> //sql中如果有运算需要单独列出来<br /> $sql = "select blog.id as blogid ,blog.title,blog.content,blog.keywords,blog.listid,blog.userid,blog.ctime,blog.yes,blog.del,list.id,listtitle from blog,list where blog.del <> '1' and blog.listid = list.id order by blog.id desc limit ". ($current-1)*$recordnum . ", $recordnum";<br /> <br /> $rs = $con->query($sql);<br /> <br /><br /> while ($row = $rs->fetch_assoc())<br /> {<br /> <br /> $newdate = date("Y-m-d", strtotime($row['ctime']));<br /><br /> <br /> echo<br /> "<tr><td><a href='./post.php?id=".$row['blogid']."' >".$row['title']."</a></td><br /> <br /> <td height='30'><a href ='./post-list.php?id=".$row['blogid']."'>".$row['listtitle']."</a></td><td>".$newdate."</td><td>黑雨</td><td><a href='./edit.php?del=".$row['blogid']." '>删除</a></td></tr><br /><br /> <br /> ";<br /> <br /> <br /> }<br /> <br /> <br /> ?> <br /><br /><br /> <br /> </table>
------解决思路----------------------
<a href="delete.php?id=<?php echo $row['id'] ?>">删除</a>
1、去掉 url 中的多余空格和引号
2、取值用 $_GET['id'],而不是 $_POST['id']
3、如果你确实想用 post 方式。那可以使用 ajax

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver CS6
Visual web development tools