Web Data Applications Practical Guide - 12


Lesson 5: Design a page to display milk information with pagination as follows:

Maybe you are interested!


Requirements analysis:

- Handle:

o Use the pager class to perform pagination, in which:

Each page consists of 5 lines of data

Export information in grid format as shown above (even and odd rows have different background and text colors, milk prices are formatted in currency.

Display page list in number format

Solution:

- Handle:

o Specify the number of lines on a page: $limit = <number of lines>

o Specify the starting position of the page:

$start = $p - >findStart($limit);

o Execute the query to get the number of records of the milk table and assign it to the variable $count

o Count total number of pages: $pages = $p ->findPages($count, $limit);

o Execute the query statement to get the records: “select … limit

$start, $limit”

o Expensive $stt = 0; // counter variable, will increase according to the number of records

o while ($row = mysql_fetch_row($result))

{ check if $stt %2 == 0 => output a line with a different background color, otherwise output a line without background color

Get and output each piece of information into each row in the table as required

Increase $stt

}

o Export page list:

$pagelist = $p -> pageList($_GET['page'], $pages);

PRACTICE SESSION NO. 9

Lesson 6: Design a page to display information about dairy products in a list format as follows:


Requirements analysis:

- Handle:

o Design and display information about dairy products as shown above, including:

Each milk is displayed on a line with two columns: an image column and a content column (with milk name, manufacturer, milk type, weight, unit price)

Solution:

- Print a table with the first row being the title row

- Browse the news items in the SUA table

o While ($row = mysql_fetch_row($result))

{

For each reviewed record, output a line with two columns, the first column is centered and is used to display the milk image sourced from the image column in the database, the second column displays information about the milk, and the milk name must be bold.

}

Lesson 7: Create a page that displays information about dairy products in columns as follows:


Requirements analysis:

- Handle:

o Design and display information about dairy products as shown above, including:

Each row has five columns, in each column there is a table displaying milk information (milk name, weight, unit price) and image

Solution:

- Export table header row in format

Set $stt = 0; // counter variable, will increase according to the number of news items

- While ($row = mysql_fetch_row($result))

{

Check if $stt % 5 == 0 -> output new line start tag

Get and output each piece of information into each column in a row of the table: In each column, output a table with three rows, the first row is the milk name (in bold), the second row is the weight and unit price formatted using the number_format(…) function , and the third row is the image whose source is taken from the image column in the database.

Increase $stt

Check if $stt % 5 == 0 -> output line end tag

}

Lesson 8: Create a page displaying information about dairy products with column links as follows:


- Create a page to display product details


Requirements analysis:

- Handle:

o Column milk page with links: Design and display information about milk products as shown above, including:

Each row has five columns, each column has a table and displays milk information and corresponding images

For each milk name, create a link to the milk detail page and pass in the milk code.

o Milk detail page/ Display milk product details as shown in the image above corresponding to the milk code obtained from the column milk page with the link passed through.

Solution:

- Column grid page with link:

…..

while ($row = mysql_fetch_row($result))

{

….

In the milk name section: create a link as follows: <a href ='list_chi_tiet_sp.php?mas =”.$mas.” '><b>$milk_name</b></a>

…..

}

- Milk detail page:

o Get milk code: $mas = $_REQUEST[“mas”];

o Get detailed information of milk with the milk code retrieved above

o Output the information that meets the condition in the required format: while ($row = mysql_fetch_row($result))

{

Output a table with three rows, the first row is the milk name (bold, centered), the second row has two columns, the first column is the image sourced from the image column in the database, the second column is the remaining information of the milk (using number_format(…) to format the price)

}

o Create a link back to the column grid page with links

Lesson 9: Create a page displaying detailed information about dairy products with pagination:


Requirements analysis:

- Design and display information about dairy products with pagination as shown above, including:

o Call using the given pager class for pagination (two products per page).

Solution:

- Specify the number of lines on a page: $limit = <number of lines>

- Specify the starting position of the page:

$start = $p -> findStart($limit);

- Execute the query to get the number of records of the milk table and assign it to the variable $count

- Count total number of pages: $pager = $p -> findPages($count, $limit);

- Execute the query statement to get the records in the milk table: “select … limit $start, $limit” and assign it to the variable $result

- Browse news items:

while ($row = mysql_fetch_row($result))

{

o For each approved piece of information, a table with two rows is output, the first row is the milk name (bold, centered), the second row has two columns, the first column is the image sourced from the image column in the database, the second column is the remaining information of the milk (using number_format(…) to format the price)

}

- Export page list:

$pagelist = $p -> pageList($_GET['page'], $pages);

Comment


Agree Privacy Policy *