Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PHP Shopping List Define an ltem class that includes the following fields: Name

ID: 3723430 • Letter: P

Question

PHP

Shopping List Define an ltem class that includes the following fields: Name Description Price Image Your class should at least have a constructor and get methods. Next, create an array of Item objects. Add the item array to a session variable. You may use the examples below or come up with your own: PriceImage 10,000 bike.jpg 54.45 shoes.jpg Name Description Porsche Bike Pretty Shoes Pie Fest! Inside Out Umbrella Designer Umbrellas for low cost Coffee bike with a brand name! Come to our shoe store Oh yeah this is officially the best pie ever 3.45 pie.jpg 14.55 umbrella.jpg 4.59 coffee.jpg Come get your morning dessert

Explanation / Answer

Create one page list.php. There you type following code
Coding of list.php

<?php

class Item {   

/* Member variables */

var $name;

var $description;

var $price;

var $image;

/* Constructor */

function __construct( $par1, $par2, $par3, $par4 ) {

$this->name = $par1;

$this->description = $par2;

$this->price = $par3;

$this->image = $par4;

}

/* Member functions */

function setName($par){

$this->name = $par;

}

function getName(){

return $this->name;

}

function setDescription($par){

$this->description = $par;

}

function getDescription(){

return $this->description;

}

function setPrice($par){

$this->price = $par;

}

function getPrice(){

return $this->price;

}

function setImage($par){

$this->image = $par;

}

function getImage(){

return $this->image;

}

}

$items = array();

array_push($items, new Item('Porche Bike', 'A bike with Brand Name!', 10000, 'bike.jpg'));

array_push($items, new Item('Pretty Shoes', 'Come to our store!', 54.45, 'shoes.jpg'));

array_push($items, new Item('Pie Fest', 'Oh yeah this is officially the besDesigner Umbrellas for low cost', 14.55, 'umbrella.jpg'));

array_push($items, new Item('Coffee', 'Come get your morning dessert', 4.95, 'coffee.jpg'));

session_start();

$_SESSION["shopping_lists"] = $items;

echo '<br><b>Shopping List</b>';

echo '<table border="0">';

foreach ($items as $key =>$item) {

echo '<tr><td>';

echo '<img src="'.$item-&gt;getImage().'" alt="'.$item->getName().'">';

echo '</td>';

echo '<td>';

echo '<a href="product_detail.php?id='.$key.'">';

echo $item->getName();

echo '</a>';

echo '</td>';

echo '</tr>';

}

echo '</table>';

?>

Put your 5 image files of same name in the same folder

Now create another file  product_detail.php and keep following code there

Coding of  product_detail.php