在数据库(mysql)中存储/生成条形码字符串
我从未使用过条形码,现在我必须设计一个支持条形码的整个应用程序。我想知道我可以使用什么类型的条形码,如何确保条形码字符串是唯一的以及如何将其存储在 MySQL 中。
我正在考虑生成一些条形码字符串并将它们打印到贴纸上,以便我的客户可以使用它们。我正在考虑在 php/mysql 中生成部分,然后准备打印(以 pdf 形式呈现)。假设我生成了 100 个字符串并将它们存储到数据库中,下次我想生成另外 200 个必须是唯一的字符串。
我什至不知道从哪里开始使用字符串。条形码字符串中可以存储哪些信息?
我可以这样做吗:XXX-ZZZZZ-YYYY-autincrementID?
其中 XXX 是国家/地区 ID,ZZZZZ 是客户 ID,YYYY 是条形码字符串 ID。我应该使用代理键作为主键还是应该将它们拆分到多个表中?
我是否提到过每个客户端的所有 autoincrementID 都应该从 1 开始:) 我对这一切感到非常困惑。
谢谢
I never worked with barcode and now i must design a whole app with barcode support. I was wondering what type of barcode i can use, how can i make shure that barcode string is uniqe and how would i store that in MySQL.
I was thinkin about generating some barcode strings and print them to stickers so my clients can use them. I was thinking to do generating part in php/mysql then prepare for printing (render in pdf). Let's say i generated 100 strings and store them to database and next time i want to generate another 200 that must be unique.
I don't even know where to begin with string. What information can i store in barcode string?
Can i do this: XXX-ZZZZZ-YYYY-autincrementID?
Where XXX is country ID, ZZZZZ is client ID, YYYY is barcode string ID. Should i use surrogative key for my primary key or should i split those to multiple tables?
Did i mentioned that all autoincrementID's should start from 1 for each client :) I am sooooo confused about all this.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先决定您要使用的条形码格式。
然后检查是否有 PHP 实现(大多数 - 如果不是全部 - 条形码格式)。
基本示例(使用 PEAR Image_Barcode)可以在 在 Web 应用程序中使用条形码。
您只需将文本存储在数据库中,就可以使用 Image_Barcode 类生成相应的图像(它支持 Code 39、Code 128、EAN 13、INT 25、PostNet 和 UPCA)。
我曾经编写过一个创建 EAN 13 条形码的应用程序,但不记得我使用了哪个库(我会在家检查是否可以找到源代码)。
First decide on the barcode format you want to use.
Then check if there is a PHP implementation out there (there will be for most - if not all - barcode formats).
A basic example (using PEAR Image_Barcode) can be found at Using barcodes in your web application.
You just store the text in the DB and can generate the corresponding image using the Image_Barcode class (it supports Code 39, Code 128, EAN 13, INT 25, PostNet and UPCA).
I once wrote an app creating EAN 13 barcodes, don't remember which lib I used though (I'll check at home if I can find the source).
我们需要区分一些关注点。
首先是将任何给定字符串打印为条形码的操作。其他答案讨论了如何做到这一点。
另一个动作与条形码无关,与数据库设计有关。您的示例表明条形码将是值的组合。然而,我认为(如果我错了,请纠正我)更大的应用程序尚未明确阐明。因此,您现在为唯一代码创建哪种“播放”表并不重要 - 创建您想要的任何内容。当您知道必须将哪些值打印为条形码时,我们就陷入了数据库设计问题。
We need to separate some concerns.
First is the action of printing any given string as a barcode. The other answers talk about how to do that.
The other action has nothing to do with barcodes and is about database design. Your example suggests the barcode will be a combination of values. However, I get the idea (correct me if I am wrong) that the larger application is not yet clearly spelled out. Therefore it does not matter what kind of "play" table you create for unique codes right now -- create whatever you want. When you know what values must be printed as barcodes, then we are into a database design question.
条形码只是打印和/或读取字符串的一种方式。它涉及
您的第一步应该是确定您需要支持的条形码。许多制造条码打印机和阅读器的公司也提供了一些相关帮助。
我在此处找到了一些很大的帮助,包括免费字体。这是一个法语网站,但有一些内容是英文的。
A barcode is just a way to print and/or read a string. It involves
Your first step should be to identify wich barcode you need to support. Many companies manufacturing barcode printers and readers also provide some help about that.
I found some great help here, including free fonts. It's a french site but a few things are available in English.