English 中文(简体)
• 如何用一栏的数值添加一个记录?
原标题:How to insert a record with a column values a autoincrement pk value?
  • 时间:2010-12-13 03:47:44
  •  标签:
  • php
  • mysql

我的桌子像以下一样,用此来挽救上载的形象。 客户希望图像成为<代码>{id}.{jp>gif}。

create table imgae(
id int autoincrement,
image text
)

怎么能够只添加一个缩略语的新记录。

最佳回答

你不能用在MySQL的单篇发言来做。 如果MySQL支持Oracle式序列,你就可以在一份声明中这样做。 但是,由于汽车的增量赢得一只 give,直到<>>><>>>之后。 添加的字句实际上需要插入字句,然后才能查阅。 在我SQL最接近的是:

insert into imgae (image) values (null);
update imgae set image=concat(last_insert_id(),  .jpg ) where id=last_insert_id();

BTW:我看见您的表格,可能称为imgae。 页: 1 而且,当我试图管理<代码>create table statement时,该表即告失败。 我不得不作两番改动,以便让我能够证实我的回答。 它希望:

create table imgae(id int auto_increment primary key, image text);
问题回答

INSERT INTO “imgae” VALUES(“image”) (CONCAT(LAST(“id”) + 1, /*code for fetching the extension/)

INSERT INTO imgae (image) VALUES (CONCAT(LAST_INSERT_ID() + 1, ".jpg"));

但是,这实际上并没有打上图像。 你们必须保证,在这样做之后,你会利用我sql_inser_id()获得这一价值。

在ID已经放在另一栏时,将id放在一栏似乎多余。 为什么不保持id,而只是担心档案延期的存放? (假定{id}.{jpg >>>>均为该栏中的内容,并作为<>text的代码表示严重错误。 然后对他们进行盘问,并编组id和分机,以取得结果。

......或我失踪





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签