根据组号和 MySQL 答案填充下拉菜单
我正在为零售商构建一个 Web 应用程序,用于在 PHP/MySQL 中注册购买的产品。 我现在喜欢做的是以特定零售商销售的产品填充表单中的下拉菜单。 零售商为他们销售的每种产品分配一个值,然后将这些值相加并放入数据库的“组”列中。 可以通过将“组”列中的数字转换为二进制来确定组成员资格,然后检查返回的字符串中特定组的特定位置。 示例:5 是二进制的 101,该值分配给数据库中的 Group 列。通过检查第一个位置是否为 1,我将确定零售商是否正在销售产品 1。注意到第二个字符是 0,我因此知道他们不销售产品 2。 由于最后一个位置是 1,我也知道他们销售产品 3。
因此,为了让零售商注册他们已销售产品 1,我想仅使用零售商正在销售的产品填充下拉框。
我确实明白我必须获取组值(使用 $_SESSION['group'] 登录时设置的二进制值)循环检查零售商销售的产品,并同时填充下拉框。我猜测 - 标签内有一个 while 循环,但是如何呢?名称(产品 1 等)及其值位于单独的表中。示例:| 1 | “产品1”| (| 代表列的开始/结束)。 关于如何做到这一点有什么想法吗?或者这样做更好吗?表中包含名称的字符串不起作用,因为字段仅限于多个字符,并且对于许多产品来说这将是一个问题。
I am building an webapplication for retailers to register purchased products in PHP/MySQL.
What I like to do now is to populate a dropdown menu in a form with the products the specific retailer sells.
The retailer is assigned a value for each product that they are selling, and then the values are summed up and putten into the database in the colum Group.
The group memberships can be determined by coverting the number in the Group column to binary and then check the specific position for a specific group in the string returned.
Example: 5 is 101 in binary, this value is assigned to the Group column in the database. By checking if the first position is a 1 I'll determine if the retailer is selling Product 1. Noting that the second character is a 0 I thereby know they ar'nt selling Product 2.
And since the last position is a 1 I also know they sell Product 3.
So for the retailer to register they've sold a Product 1, I want to populate a dropdownbox with only the prducts that retailer is selling.
I do understand I have to get the groupvalue (the binary value is set when loggin in using the $_SESSION['group']) loop it through to check wich products the retailer sells and in the same time populate the dropdownbox. I'm guessing a while loop inside the -tag, but how? The names (Product 1 and so on) are in a separate table with their values. Example:| 1 | "Product 1" | (the | are representing columns start/end).
Any idea on how to do this? Or is it someway better to do this? A string in the table with the names wont work since the fields are limited to a number of chars and with many products that will be a problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没关系,将组系统重新制作为使用单独的表。
现在,就像一个魅力一样,有一个用于组的表、一个用于用户的表和一个将它们链接在一起的表。
Nevermind, remade the groupsystem into using separate tables instead.
Now working like a charm with a table frou groups, a table for users and a table to link them together.