从单元格获取数据
我有一个名为“设置”的数据库表,在该表中我有 2 列。示例图片:
如您所见,第一列称为“setting_name” ”,第二个称为“setting_value”。
我该怎么办,所以每当我写 example: 时,
echo $setting['ad_cost_micro'];
它都会打印出:
0.00200
顺便说一句。是否可以不使用 while 语句?
I have a database table called "settings", and in that table I've got 2 columns. Example picture:
As you can see, the first columns is called "setting_name" and the second is called "setting_value".
How can I do, so whenever I write example:
echo $setting['ad_cost_micro'];
It will print out:
0.00200
Btw. is it possible to do without a while statement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我倾向于使用 PDO 和 fetchAll()。
注意:无论您使用什么,while 循环是不可避免的,因为您必须循环遍历结果集 (
fetchAll()
),而且要知道每个循环是一个 while 循环(甚至是 for 循环!)。I tend to use PDO, and
fetchAll()
.Note: Regardless of what you use, a while loop is unavoidable because you HAVE to loop through the result set (
fetchAll()
) does that too, also, know that every loop is a while loop (even for loops!).如果 mysqli 可用...
编辑:删除 while 代替 for
if mysqli is available...
EDIT: removed while in place of for
看不到截图,但也许...
Can't see the screenshot but maybe...