如若根据数据库里的数据显示不同的图片

WBOY
Release: 2016-06-13 10:56:54
Original
982 people have browsed it

如果根据数据库里的数据显示不同的图片
我有3种类型的数据
是手机端用户可以选择的(图片)
在数据库type字段里显示的是1,2,3 (一共有8种状态 用户只能选4个 也就是进数据库时只能是只有4个数据 如1,2,3,4 或者1,2,3 也可以0,0,0,0 代表什么都没选)。

我想问:
怎么在控制层里面把字段提取出来 并在VIEW层里显示相应的图片(图片在本地)
新手 回答要详细哦!

------解决方案--------------------
在控制器直接查询这个表就好了,然后取出type字段的数据是个字符串,$c=explode()转换成数组
在项目里随便建个php文件,然后在里面写个新数组,如
$a=array(
1=>'/images/1.png',
2=>'/images/2.png',
3=>'/images/3.png',
4=>'/images/4.png',
5=>'/images/5.png',
6=>'/images/6.png',
7=>'/images/7.png',
8=>'/images/8.png',
);
include引用创建文件
遍历数组当$c的value值等于$a的k值记录到一个新的二维数组,然后在视图遍历这个数组就得到图片的路径

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!