duanhuokuang5280 2012-03-23 22:18 采纳率: 100%
浏览 79
已采纳

php删除mysql数据库中的行

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);
?>

What i'm really trying to do is this:

  • 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 :(

  • 写回答

6条回答 默认 最新

  • doume5227 2012-03-23 22:30
    关注

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?