PHP practice 5


Make a function to load product list, filter products by companies


I. General

In this practice, I will introduce one method programming access database to load products in database and show up as a menu. About display data, we have to follow the design of html project. Otherwise, I am also introduce a method filter products by companies.  A small note here, filter data usually get available from url so It is very easy mistake SQL-Injection. To solve that problem, usually refer security category in this website.

II. Implement

1. Create table to stores information of products

To stores information of products you have to create table in MySQL and put its name is sanpham. Including: id: primary key, auto increment; tensp: stores name of products; gia: price of products; mota: describe for products; idcty: stores id for congty table.

I want you know it is information very basic for one table. In real project, it need more like discount, suggest… You should research how to make a good database. Otherwise, for filter data usually get available from url so sometimes mistake  SQL-Injection. To sole that one, refer security category in this website.

2. Design formatting for show up products

To have one formatting “simple” for show up small information of products, follow the designing below:

css layout

Result of this design:

css layout result

3. Make a function to load products from database

Loadrightproduct were built base on two issues: access to database, design formatting show up data.

php practice 4 source code

4. Video for more details

5. Results
php practice 5 result

Have fun and good luck.