Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Php script to read the list of item names and corresponding price and to find the cheapsest and

costliest item

HTML COde

<html>

<head>

</head>

<body>

<form method=post action="Item_Listing.php" >

<p>

Enter the List of Items <br> ( seoerated with space )<br>

<input type=text name=items >

</p>

<p>

Enter the coreesponding price of Items <br> ( seoerated with space )<br>

<input type=text name=prices >

</p>

<p>

<input type=submit > <input type=reset>

</p>

</form>

</body>

</html>
PHP script

<?php

$itemname=$_POST['items'];

$itemprice=$_POST['prices'];

if(empty($itemname)||empty($itemprice))

die(" Please fill all the fields ");

$itemsA=explode(" ",$itemname);

$priceA=explode(" ",$itemprice);

$item_count=count($itemsA);

$price_count=count($priceA);

if($item_count!=$price_count)

die("The number of items and the number of prices should match ");

echo " <table border=2 >";

echo " <tr><th colspan=2 ><h4>ABC Coperative Stores </h4></th></tr>";

echo " <tr><th>Item Name</th><th>Item Price</th></tr>";

for($i=0;$i<$item_count;$i++)

echo "<tr><td>". $itemsA[$i]." </td> <td>". "Rs ". $priceA[$i]. "</td></tr>";

echo "</table>";

$maxp=max($priceA);

$minp=min($priceA);

for($i=0;$i<$item_count;$i++)

if($maxp==$priceA[$i])

echo "<br>"."Costliest Item is -- ". $itemsA[$i];


if($minp==$priceA[$i])

echo "<br>"." Cheapest Item is -- ". $itemsA[$i];

?>

You might also like