sql isn n New数据现有数据,误差

发布于 2025-02-02 05:11:21 字数 738 浏览 6 评论 0原文

我正在使用此代码通过PHP插入SQL数据库中的

$sql="INSERT INTO $tbl_name(cid, instrument, otime, volume, oprice, type, ctime, cprice, commission, swap, profitloss)VALUES('$pcid', '$pinstrument', '$potime', '$pvolume', '$poprice', '$ptype', '$pctime', '$pcprice', '$pcommission', '$pswap', '$pprofitloss')";

所有代码互相插入的所有数据,这意味着插入的第一个记录是在表格的顶部,然后是第二个bellow等。等。当我删除一行时,问题出现了,也是通过PHP使用下面的代码,然后将新记录插入旧记录的位置,而不是表的底部。

$sql="DELETE FROM $tbl_name WHERE id='$id'";

有人知道为什么吗?附加了有关我的数据库的更多信息 picture1 pciture2

I'm inserting data into my sql database through php using this code

$sql="INSERT INTO $tbl_name(cid, instrument, otime, volume, oprice, type, ctime, cprice, commission, swap, profitloss)VALUES('$pcid', '$pinstrument', '$potime', '$pvolume', '$poprice', '$ptype', '$pctime', '$pcprice', '$pcommission', '$pswap', '$pprofitloss')";

All data inserted came after each other, meaning first record inserted is at the top of table then second bellow it and etc. the problem came when I deleted a row, also through php using the code below, afterwards new records are inserted in the place of the old records, not at the bottom of the table.

$sql="DELETE FROM $tbl_name WHERE id='$id'";

Anybody knows why? attached more info about my databasepicture1 pciture2

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

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

发布评论

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

评论(1

妄想挽回 2025-02-09 05:11:21

技巧

按子句订购是我正在使用的

$sql="SELECT * FROM $tbl_name";

,但是当我添加订单成为此过程时,

$sql="SELECT * FROM $tbl_name ORDER BY id";

它可以根据需要工作。

归功于Barmar的提示

Order by clause is the trick

I was using

$sql="SELECT * FROM $tbl_name";

But when I added ORDER BY to become this

$sql="SELECT * FROM $tbl_name ORDER BY id";

It worked as desired.

Credit to Barmar for the hint

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