动态值动态数组PHP?
我有数据库 MySQL,在其中一个表字段中我有一个建议,其值类似于“13095,11413,11424,11434”或“1344,14513,11423”
值中的数字是我的产品ID,好的,现在我需要要为每个数字执行 while 循环并将其打印在表格中,我可以执行 while 循环来检索产品信息,但是我怎样才能单独获取每个数字进行检索吗?我想如果我使用数组我可以解决我使用PHP的问题
:
$sug = $row['SuggestProduct'];
$asug = array($sug);
但是这里 array[0] = "13095,11413,11424,11434"
I have database MySQL and in one of the tables fields I have a suggestions which have values like this "13095,11413,11424,11434" or "1344,14513,11423"
The number in the values are my productID, ok now I need to do a while loop for each number and print it in a table, I can do the while loop to retrieve the product information, but how could I get the numbers each one alone to do the retrieving? I thought that if I used array I may solve the problem I used
PHP:
$sug = $row['SuggestProduct'];
$asug = array($sug);
but here array[0] = "13095,11413,11424,11434"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然爆炸是你的朋友,但你应该考虑以不同的方式存储建议。对“多对多”关系进行一些研究。
上述程序的解决方案是
$suggestions =explode(',', $row['SuggestProduct']);
While explode is your friend, you should consider storing the suggestions differently. Do some research on "many to many" relations.
Solution for the above program is
$suggestions = explode(',', $row['SuggestProduct']);