If different images are displayed based on the data in the database

Source: Internet
Author: User
If different images are displayed based on the data in the database, three types of data are available for mobile phone users (images). in the database type field, 1, 2 are displayed, 3 (in a total of 8 states, users can only select four, that is, when they enter the database, they can only have four data records, such as 1, 2, 4, or 1, 2, 3, or 0, 0, 0 indicates that nothing is selected ). I would like to ask: how can I display different images at the control layer based on the data in the database?
I have 3 types of data
It can be selected by mobile phone users (images)
In the database type field, 1, 2, and 3 are displayed. (in a total of 8 states, a user can only select four. that is, when entering the database, only four data items can be selected, such as 1, 2, 3, 4, or 1, 3 can also be 0, 0, 0 indicates that nothing is selected ).

I want to ask:
How to extract the field from the control layer and display the corresponding image in the VIEW layer (the image is local)
The answers should be detailed!

------ Solution --------------------
Query the table directly on the controller, and then retrieve the data of the type field as a string, and convert $ c = explode () to an array.
Create a php file in the project and write a new array in it, as shown in figure
$ 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 references to create files
Traverse the array. when the value of $ c is equal to the K value of $ a, it is recorded to a new two-dimensional array. then, traverse the array in the view to obtain the image path.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.