View Single Post
Old 01-24-2007, 02:09 AM  
calmlikeabomb
Confirmed User
 
calmlikeabomb's Avatar
 
Join Date: May 2004
Location: SW Palm Bay, Florida
Posts: 1,323
This would probably suit your first question a little nicer:

Again, assuming you've already got the db connection established...

Quote:

<?

ob_start();

/* Generally with apps like you are making you want to store all information in the database and calculate totals such as total items in inventory, total sales, total debt ect on the fly. Cause it's information that is constantly changing and would be a real pain if you had to edit the source file of your app each time you made some $$, sold an item, restocked, got something new in stock, etc.

Make a separate table for your items with fields such as ID, ItemTitle, Description, Onhand, Warehouse, Cost, etc (a field for each piece for product information you will be storing). With that being said let's iterate through the products table rows and create a clickable list of products that will take us to a page for viewing more information (could just as easily be a form for editing the product. We will assume this file is called admin.php make sure this file is protected with cookies, sessions, http authentication, .htaccess, whatever. */

if(!isset($_GET['item'])) {//Not viewing a specific item so show the item list.

$res=mysql_query("SELECT ID, ItemTitle FROM ProductsTable");
while($row=mysql_fetch_assoc($res)) {$x++;
$ItemMenu .="$x) <a href=\"admin.php?item=$row[ID]\">$row[ItemTitle]</a><br/>";

}

print $ItemMenu;

unset($res, $row, $x);

}else{/* We are viewing an item. Here you can show all the items details or even a form that allows you edit the item with an UPDATE query. */

$res=mysql_query("SELECT * FROM ProductTable WHERE ID='$_GET[item]' LIMIT 1");

if(mysql_num_rows($res) < 1) {//If no matching record is found redirect to admin.php

header("Location: admin.php"); ob_flush(); exit();

}else{//Item has been located, store row details into associative array.

$Item=mysql_fetch_assoc($res);

/* Now here is where you gotta get creative. You've got the record pulled from the database now along with all the details from each field. You just gotta refer to them like this inorder to use the information: $Item[FieldName]*/

echo"Title of Item: $Item[ItemTitle] <br/> OnHand Stock: $Item[OnHand]<br/>,etc of course use any html you want just refer to the $Item[] array to access your item details.";

}

/* Hope this can get ya going. BTW, I didn't execute any of that code. Let me know if you have any problems - I did glance for bugs, but didn't use an editor to type it (easier to over look syntax errors if the editor doesn't do color coding). Keep us advised.. */

?>


Last edited by calmlikeabomb; 01-24-2007 at 02:12 AM..
calmlikeabomb is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote