PHP从MySQL数据库删除链接行 [英] php delete links rows from mysql database

查看:91
本文介绍了PHP从MySQL数据库删除链接行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从mysql中删除一些数据.我知道一点点php,但是由于mysql而迷失了,真的不想把它弄乱……我确实做了.sql备份,但是我需要正确解决这个问题.这就是为什么我在这里发布问题.我知道我会因为不尝试自己并在这里发布我的代码而变得不诚实而得到一些废话..这是我被困之前所得到的:

I need to delete some data from mysql. I know a bit of php but get really lost with mysql and really don't want to mess this up... I did make a .sql backup but I need to get this right. That's why i'm posting the question here. I know I will get some crap for not trying myself and posting my code here but to be hosnest.. this is as far as I got before I got stuck:

<?php
$con = mysql_connect("localhost","USERNAME","PASSWORD");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("DATABASE", $con);

$result = mysql_query("SELECT * FROM subscriber");

while($row = mysql_fetch_array($result))
  {
  echo $row['mail'] . " " . $row['snid'];
  echo "<br />";
  }

mysql_close($con);
?>

我真正想做的是:

  • 在名为subscription的表中找到status = 0的所有行,并获取字段snid(是整数)
  • 然后转到名为subscriber的表,并删除具有匹配的snid的行(此表行中的一个字段)
  • 然后返回subscription并删除原始匹配的行
  • Locate all rows where status = 0 the in the table called subscription and get the field snid (which is an integer)
  • Then go to the table called subscriber and delete the row with the matching snid (also a field in this tables row)
  • Then go back to subscription and delete the original matched row

这有意义吗?...我只是想解释一下而已:(

Does this make sence?.... I've done my own head in just trying to explain it :(

推荐答案

要执行您所要求的操作,只需执行1个查询:

To do what you've asked, you only need 1 query:

delete subscriber, subscription from subscriber,subscription where subscription.status = 0 and subscription.snid=subscriber.snid;

这篇关于PHP从MySQL数据库删除链接行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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