mySql删除仅删除数据而不是整个条目

发布于 2024-08-27 18:56:18 字数 577 浏览 6 评论 0原文

大家好,我的 php 代码中有这一行,

 `$insert = "DELETE FROM allocation_table WHERE job = '$jobnumber' " ;
  Mysql_query ($insert) ;`

问题是它将删除表中这一行的所有值,但不会删除条目本身。正如您在图片中看到的,如果我删除 where job = 315 ,它不会删除该行,但会删除

它前面的代码中的所有条目(另一个表)。它工作正常,整条线都被删除了,

$insert = "DELETE FROM event WHERE jobnumber = '$jobnumber' " ; 
mysql_query ($insert) ;enter code here

有人可以提供一些建议吗? 替代文本 http://img34.imageshack.us/img34/4431/tablenj.jpg< /a>

Hi all I have this line in my php code

 `$insert = "DELETE FROM allocation_table WHERE job = '$jobnumber' " ;
  Mysql_query ($insert) ;`

The problem is it will remove all the values from the one line in my table but not the entry itself. as you can see in the picture if I delete where job = 315 , it does not delete the line but does delete all the entries

Yet in this code that preceeds it (a different table) . it works fine and the whole line is removed

$insert = "DELETE FROM event WHERE jobnumber = '$jobnumber' " ; 
mysql_query ($insert) ;enter code here

can anyone offer some advice please ?? alt text http://img34.imageshack.us/img34/4431/tablenj.jpg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

贱贱哒 2024-09-03 18:56:18

您的代码中有错误处理例程吗?
您可能还想添加一些调试输出(或者更好地使用 xdebug 等调试器)
(过于简化)示例:

$insert = "DELETE FROM allocation_table WHERE job = '$jobnumber' " ;
echo '<pre>Debug: query=', htmlspecialchars($insert), '</pre>';
$rc = mysql_query($insert);
if ( !$rc ) {
  echo '<pre>mysql_query failed: ', mysql_error(), '</pre>';
}
else {
  echo '<pre>Debug: affected rows=', mysql_affected_rows(), '</pre>';
}

$insert = "DELETE FROM event WHERE jobnumber = '$jobnumber' " ; 
echo '<pre>Debug: query=', htmlspecialchars($insert), '</pre>';
$rc = mysql_query($insert);
if ( !$rc ) {
  echo '<pre>mysql_query failed: ', mysql_error(), '</pre>';
}
else {
  echo '<pre>Debug: affected rows=', mysql_affected_rows(), '</pre>';
}

Do you have any error handling routines in your code?
You might also want to add some debug output (or even better use a debugger like xdebug)
(oversimplified) example:

$insert = "DELETE FROM allocation_table WHERE job = '$jobnumber' " ;
echo '<pre>Debug: query=', htmlspecialchars($insert), '</pre>';
$rc = mysql_query($insert);
if ( !$rc ) {
  echo '<pre>mysql_query failed: ', mysql_error(), '</pre>';
}
else {
  echo '<pre>Debug: affected rows=', mysql_affected_rows(), '</pre>';
}

$insert = "DELETE FROM event WHERE jobnumber = '$jobnumber' " ; 
echo '<pre>Debug: query=', htmlspecialchars($insert), '</pre>';
$rc = mysql_query($insert);
if ( !$rc ) {
  echo '<pre>mysql_query failed: ', mysql_error(), '</pre>';
}
else {
  echo '<pre>Debug: affected rows=', mysql_affected_rows(), '</pre>';
}
躲猫猫 2024-09-03 18:56:18

也许您的 MySQL 表上有一些奇怪的设置,导致查询的功能不同。该表是您自己创建的(使用 PMA?)还是从其他地方导入?

当您使用 PHPMyAdmin 删除时,它运行的查询是什么?

Maybe you have some weird setting on your MySQL table that is causing the query to function differently. Did you create the table yourself (with PMA?) or import it from somewhere else?

When you delete using PHPMyAdmin, what is the query that it runs?

清音悠歌 2024-09-03 18:56:18

尝试在 PhpMyAdmin 中删除,看看会发生什么。至少在那里您可以轻松地看到任何错误消息。

您是否定义了外键和/或表约束?

Try deleting in PhpMyAdmin and see what happens. At least there you'll be able to easily see any error message.

Do you have foreign keys defined and/or table constraints?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文