Coding solution for a challenging PHP assignment

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 2
Joined: Thu Nov 21, 2013 4:47 am

Coding solution for a challenging PHP assignment

Postby poonam123 » Thu Nov 21, 2013 5:03 am

Hi All,
Here is my problem for a PHP assignment given to me. I hope somebody can help me with coding solution.

Till now I have created a class to display the product description ;location and current stock leve;..

I don't know how to let the user chose only 5 different products for creating an order and show a warning if the products have run out.
The solution must use an oops approach..doing otherwise is pretty easy..

Here is my class and code to fetch the data.

1) Create a database of 60 products, assign each a stock level and a unique Bin location from the range A1 – F10 (see warehouse floorplan).

2) Provide a method for querying a product/bin location which returns the product description, bin location and current stock level.

3) Provide a method for creating an order. An order will always consist of 5 different products chosen by the user.

4) If there is insufficient stock available to fulfil the order display a warning message, otherwise decrease the relevant stock levels and calculate/display the optimum picking route.

The optimum picking route must start from one of the pick stations (P1, P2, P3), and is the shortest number of steps needed to 'pick' all of the products before returning to the original pick station.

5) The user interface must be web based.

6) Write a short paragraph about the scalability of your solution, i.e. How would the implementation handle a much bigger warehouse?

7) An object oriented approach must be demonstrated.

8) The task must be completed using PHP 5 and mySQL 5. Please send the SQL and PHP files as well as upload the solution to a server. If you do not access to a server, we can provide you with access to one for the purposes of this task.

Please refer to diagram 1 for an example of a simple warehouse floor plan.

The warehouse consists of 6 racks of product bins A1-F10. Each product bin holds a unique type of product – a product is only accessible by standing directly in front of the product bin.

e.g A 'picker' standing at position 'X' can pick from product bins B6 and C6, whereas a picker standing in position 'Y' cannot pick from anywhere.

The order picking procedure is as follows:
A 'pick sheet' will print at the packing station P1, P2 or P3 & be collected by a picker. The pick sheet lists all products required for an order, the bin location for each product & the route the picker should follow.
When all items have been picked, the picker returns to the packing station where they collected the original pick sheet & deposits all items.

Note: Pickers can walk directly through the packing stations, but they cannot walk directly through any racking or product bins!

A10 B10 C10 D10 E10 F10
A9 B9 C9 D9 E9 F9
A8 B8 C8 D8 E8 F8
A7 B7 C7 D7 E7 F7
A6 B6 X C6 D6 E6 F6
A5 B5 C5 D5 E5 F5
A4 B4 C4 D4 E4 F4
A3 B3 C3 D3 E3 F3
A2 B2 C2 D2 E2 F2

A1 B1 C1 D1 E1 F1

P1 P2 P3

Diagram 1: Simple warehouse floor plan
Key: m is the distance in metres.
P1, P2, P3 Picking Station coded purple
A1-F10 Product bins coded yellow

class product_bin_class
private $set_host;
private $set_username;
private $set_password;
private $set_db;

public function __construct($set_host,$set_username,$set_password)
$this -> host = $set_host;
$this ->username=$set_username;
$this ->password=$set_password;
if($this ->connect=mysql_connect($this->host,$this->username,$this->password))
return "connected";
return "not connected";
public function database($set_db)
$this ->db= $set_db;
mysql_select_db($this ->db, $this ->connect) or die (mysql_error());

public function fetch_and_display($set_tablename)
$query= mysql_query("select * from ".$set_tablename);
$result = array();
while ($data=mysql_fetch_array($query))
return $result;


include ("product_bin_class.php");
$pbin_class= new product_bin_class('localhost','root','root');
$pbin_class -> database('test');
$result = $pbin_class -> fetch_and_display('product_bin');
echo '<table>';
echo '<tr><th>Product ID' . '</th><th>Product Desc' . '</th><th>Product Desc' . '</tr>';
echo '<form action="product_bin_class.php" method="POST"><b>Pick Only Two Please!</b> ';
echo '<input name="placeorder" type="hidden">';
for ($x = 0; $x < count($result); $x++)

echo '<tr>';
echo '<td>' . $result[$x][0] . '</td><td>' . $result[$x][1] . '</td><td>'.$result[$x][3];

// :Begin - dynamic checkbox generation for deleting staff
echo '<td>';
echo '<input type="checkbox" name="checkbox[]" value="' . $result[$x][0] . '"/>';
echo '</td>';
// :End
echo '</tr>';
echo '<tr align="right"><td colspan="3"><input type="submit" name="Order" value="Order" onclick= "hello()"; value="Click to Release";"/></td></tr>';
echo '</form>';
echo '</table>';
//echo "User chose $n items from the list.<br>\n" ;
if(isset($_POST['Order'])) {
echo "show Order";
if(sizeof($_POST['checkbox']) == 5) {
echo "Item $i=".$listvals[$i]."<br>\n";
} else {
echo "error, pick exactly 5 items!";
<script type="text/javascript">
function hello()
alert ("hello");

Can somebody please guide me what other classes should I create and how should i restrict the user's choice to 5 items and how do i choose the shortest route.


Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot] and 4 guests