English 中文(简体)
我怎样才能在数据库的一栏中存储一些数字作为ID,然后逐个得到它们呢?
原标题:How can I store some sets of numbers as IDs in a column in database and then get them one by one?

I want to store some sets of numbers as file IDs in just one column and put a "," after them to make them separate. like : 8546, 5654, 2311, 7544, 6565, .... But in retrieving them, I want to get each ID separately. Is it possible?

问题回答

在数据库列( Mysql) 中存储数据,并在 php 中使用爆炸函数从该列中读取该数据集。 但是, 这样的存储数据不是好主意, 您必须在单独的列中分别存储, 您可以创建另一个带有父表格前缀密钥的表格, 并在该表格上扭曲这些 id s 。

您也许应该另开一张带有 id 的表格, 这样您就可以从此表格和该表格中选择 select id, 如果您想只用 MySQL 来做的话 。

如果这只是 Mysql, 请尝试正则表达式 :

http://dev.mysql.com/doc/refman/5.1/en/regexp.html

我不明白你在做什么,或者你为什么要这么做,但这正是我要做的。用某种反射器来追踪你所在的逗号,然后将柜台的金额记在正负数上。

这是如果这只是 Mysql, 如果你有php, c#, java, python, 任何其他语言, 你可以象征。

这是可能的,但它不建议99%。

你可以做这个爆炸, I. E:

insert into table1(id) values ("1,2,3,4,6,7,8,9")

ID 字段不能是一个数字字段类型, 可能一个 varchar 可能是一个很好的选项。 对于 Mysql 来说, 这些值的文本多于数字 。

< 强 > BUT

如果你们做了你们所犯的错误,因为你们是错的。

  • You are not making a relational database.
  • You are losing the index, and the search will be slower.
  • you are creating dependence in your code, if you want to upgrade, add new things it s not going to be easy at all.

请查看实体关系模型或E/R模型。

如果您必须将此功能保留在数据库中, 您可以使用一个程序 。 < a href="http://forge.mysql.com/tools/tool.php?id=4" rel="nofollow" > 这里有一个例子 将字符串拆分并插入到表格中。 如果您想要一次调用, 您可以在程序内将表格创建为 TEMPORary Table , 从中选择返回程序内的结果, 然后在退出前将其丢弃 。

"要它为我工作,我需要删除评论部分。 "





相关问题
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 ...

热门标签