Location: PHPKode > projects > Grocery List > GroceryList.php
<?php
########################################################################
#
# Project: Grocery List
# URL: http://sourceforge.net/projects/grocery-list/
#
# Copyright: (C) 2007, James Campbell
# License: GNU General Public License Version 3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Filename: $URL: https://grocery-list.svn.sourceforge.net/svnroot/grocery-list/releases/1.0/GroceryList.php $
# Last Updated: $Date: 2010-03-06 00:03:07 -0800 (Sat, 06 Mar 2010) $
# Author(s): James Campbell
#
########################################################################

$title = 'List Home';
$onload = 'list.Item.focus();';
include_once("include/header.php");
?>


<p>Scan Barcode or Type the Name of Item to Add</p>
<form name="list" action="GL_additem_Form.php"><input maxlength="100" name="Item"> <input value="Add Item" name="AddItem" type="submit"></form>


<?php

$select = isset($_POST["select"]) ? $_POST["select"] : "";

$connection = dbconnect();
$sql = "select * from groceries";
//$sql_result = mysql_query($sql, $connection) or die ("Couldn't execute query.");
$sql_result = $connection->query($sql);

echo "<FORM method=\"POST\" action=\"\">";

if($select == "Select All")
{
	
	$selectval = "Select None";
	$check = 1;
	
}
else
{
	$selectval = "Select All";
	$check = 0;
}

echo "<TABLE BORDER=1 align=\"center\">";
echo "<TR><TH><input name=\"select\" value=\"$selectval\" type=\"submit\"></TH><TH>Item ID</TH><TH>Qnt</TH><TH>Name</TH><TH>Size</TH><TH>MFCTR</TH><TH>Notes</TH><TH>Time Added</TH><TH></TH></TR>";
echo "</FORM>";


echo "<FORM method=\"POST\" action=\"GL_edititem_Form.php\">";


foreach ($sql_result as $row)
{
	$itemid = $row["itemid"];
	$quan = $row["quantity"];
	$name = $row["itemname"];
	$size = $row["size"];
	$units = $row["units"];
	$mfctr = $row["manufacturer"];
	$notes = $row["notes"];
	$time = getElapsedString(strtotime($row["time"])) . " ago";

	if($mfctr == NULL) { $mfctr = "N/A"; }
	if($notes == NULL) { $notes = "N/A"; }

	$editnum = sprintf("Edit %s",$itemid);
	$chkboxname = sprintf("chkbox%s",$itemid);

	if($check == 0)
	{
		echo "<TR><TH><input name=\"cb[]\" value=$chkboxname type=\"checkbox\"></TH><TH>$itemid</TH><TH>$quan</TH><TH>$name</TH><TH>$size $units</TH><TH>$mfctr</TH><TH maxsize=\"20\">$notes</TH><TH>$time</TH><TH><input name=\"edititem\" value=\"$editnum\" type=\"submit\"></TH></TR>";
	}
	else
	{
		echo "<TR><TH><input name=\"cb[]\" value=$chkboxname type=\"checkbox\" checked></TH><TH>$itemid</TH><TH>$quan</TH><TH>$name</TH><TH>$size $units</TH><TH>$mfctr</TH><TH maxsize=\"20\">$notes</TH><TH>$time</TH><TH><input name=\"edititem\" value=\"$editnum\" type=\"submit\"></TH></TR>";
	}
}	

//mysql_free_result($sql_result);




echo "</TABLE>";
$sql = "select count(*) from groceries";
//$sql_result = mysql_query($sql, $connection) or die ("Couldn't execute query.");
$sql_result = $connection->query($sql);

//$row = mysql_fetch_array($sql_result);
//mysql_free_result($sql_result);

//$cnt = $row[0];
$cnt = $row[0][0];

if($cnt == 0)
{
	echo "<p>No Groceries In The List</p>";
}

echo "<input value=\"Delete\" name=\"ItemFunc\" type=\"submit\">";
echo "<input value=\"Print\" type=\"button\" onclick=\"window.print()\">";
//echo "<input value=\"Send\" name=\"ItemFunc\" type=\"submit\">";
echo "</FORM>";


//mysql_close($connection);
$connection = NULL;

include_once($WEBROOT . "/include/footer.php");

?>
Return current item: Grocery List