前端mysql,删除一行 [英] front end mysql, deleting a row

查看:105
本文介绍了前端mysql,删除一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个前端来查看 mysql 数据库,其中包含按特定条件(例如年龄和性别)过滤的选项以及删除数据库中特定条目的选项.

我使用了这个 http://www.tizag.com/ajaxTutorial/ajaxxmlhttprequest.php 作为构建一切的指南.

到目前为止,这是我所拥有的:view.php - 验证用户,使用输入框创建基本 html 以定义过滤器、提交按钮、从输入框中读取值并调用 ajax.php 的 javascript 函数、基本 html 以显示 mysql 查询的结果.

ajax.php - 连接到 mysql 数据库,从 view.php 获取输入值,根据输入值构建 mysql 查询,创建一个表,由 view.php 显示所有 mysql 查询结果.

在 mysql 查询结果的每一行中,我有一个 html 输入按钮,onclick 调用用于删除特定行的 javascript 函数.所以每一行都有自己的删除按钮.这个删除函数现在驻留在 view.php 中.

我的意图是,delete js 函数将调用另一个文件,例如 delete.php,delete.php 将激活 mysql 查询以根据单击的删除按钮删除特定行.

我唯一不能正常工作的部分是如何将正确的行 ID 传递给 delete.php.

有什么想法吗?

解决方案

在通过php生成的每个按钮的onclick事件中,将行ID存储为发送该按钮的函数的参数delete.php 的参数.

示例:

在生成每个删除按钮的 php 中:

echo '

然后在您的 javascript 中创建相应的 AJAX 函数 delete(row_id),它将将该参数作为请求的一部分传递给您的 delete.php.

i'm creating a front end to view a mysql database with options to filter by certain criteria (such as age and sex) as well as options for deleting specific entries in the database.

i used this http://www.tizag.com/ajaxTutorial/ajaxxmlhttprequest.php as a guide to build everything.

so far this is what i have: view.php - authenticates user, creates basic html with input boxes in order to define the filters, a submit button, javascript function that reads the values from the input boxes and calls ajax.php, basic html to display results of mysql query.

ajax.php - connects to the mysql DB, gets the input values from view.php, builds the mysql query from the input values, creates a table of all the mysql query result which is displayed by view.php.

within each row of the mysql query result, i have an html input button which, onclick, calls a javascript function intended for deleting the specific row. so each row has it's own delete button. this delete function right now resides in view.php.

my intention, is that the delete js function will call another file, say delete.php and that delete.php will activate the mysql query to delete the specific row based upon which delete button was clicked.

the only part i don't have working correctly is how to pass the correct row ID to delete.php.

any thoughts?

解决方案

In the onclick event of each button which is generated through php, store the row ID as the parameter of the function which sends that parameter to your delete.php.

Example:

In the php which generates each of your delete buttons:

echo '<input type="button" value="Delete" onclick="delete('. $row_ID .')" />';

Then just make the corresponding AJAX function delete(row_id) in your javascript which will pass that parameter as part of the request to your delete.php.

这篇关于前端mysql,删除一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆