简体   繁体   English

php mysqli输入行号到备用列

[英]php mysqli input row number in to alternate column

My database is set up like this 我的数据库设置如下


article_id     article_name     article_seo

    12            test a         /test-a

I would like for the article_seo to have the article id within it! 我想让article_seo在其中包含文章ID!

$articleseo=$article_id.'/'.$newurltitle.'.html'; // article_id is undefined

so when it is uploaded to the database it will look like this 所以当它上传到数据库时,它将如下所示


article_id     article_name     article_seo

    12            test a         12/test-a

So my question is what what the variable $article_id have to be in order to achieve this 所以我的问题是变量$ article_id必须是什么才能实现这一目标

is the article_seo artribute the way you show the link to the article page? article_seo artribute是您显示文章页面链接的方式吗? If so, none of this should be stored in the database in the first place, and instead it should be part of the code. 如果是这样,那么首先不应该将这些存储在数据库中,而应该是代码的一部分。 That would help you with your question too, since the link would be created when displaying the data, so there's no need to work around this issue. 这也可以帮助您解决问题,因为在显示数据时会创建链接,因此无需解决此问题。

If you want/need to do this anyway, and if you are distributing ids in increments (auto_increment), you can use MySQL Trigger to get the id of the next item assigned, which will correspond to the last article. 如果你想要/需要这样做,并且如果你以增量(auto_increment)分配id,你可以使用MySQL Trigger来获取分配的下一个项目的id,这将对应于上一篇文章。

If you are trying to use the value of the auto-incremented id field in another field, the only way I've found to do it is with a second query after asking mysqli for that value with "$mysqli->insert_id". 如果你试图在另一个字段中使用自动递增的id字段的值,我发现这样做的唯一方法是在使用“$ mysqli-> insert_id”向mysqli询问该值后再进行第二次查询。

http://php.net/manual/en/mysqli.insert-id.php http://php.net/manual/en/mysqli.insert-id.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM