colleyboy Posted July 8, 2010 Share Posted July 8, 2010 Hi there. I have made a stock management system fine but I want to add a column on the left with a hyperlink so that when they press the "Reduce Quantity" button it reduced the integer in the mysql table by one. The table name is "stock" and the field name is "fax". (I was going to store names and addresses etc then changed my mind). This is the sc for index.php: <? session_start(); if(!session_is_registered(myusername)){ header("location:main_login.php"); } ?> <BODY BGCOLOR="YELLOW" LINK="BLACK" ALINK="BLACK" VLINK="BLACK"> <CENTER><IMG SRC="images/logo.png"></CENTER><BR> <font face="Verdana" size="2"> <CENTER><A HREF="index.php">Master Database</A> | <A HREF="add.html">Add New Product</A> | <A HREF="search.php">Search For A Product</A>| <A HREF="logout.php">Logout</A> </CENTER> <BR> <CENTER><B><U>Master Database</U></B></CENTER><BR> <FONT FACE="VERDANA" SIZE="2"> <? include("dbinfo.inc.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM contacts"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table border="2" bordercolor="black" cellspacing="2" cellpadding="2" WIDTH="100%"> <tr> <th><font face="Verdana" size="2"><B>Barcode</font></th> <th><font face="Verdana" size="2"><B>Item Description</font></th> <th><font face="Verdana" size="2"><B>Location</font></th> <th><font face="Verdana" size="2"><B>In-Store Price</font></th> <th><font face="Verdana" size="2"><B>Retail Price</font></th> <th><font face="Verdana" size="2"><B>Quantity</font></th> <th><font face="Verdana" size="2"><B>Dealer Name</font></th> <th><font face="Verdana" size="2"><B>Modify</font></th> <th><font face="Verdana" size="2"><B>Delete</font></th> </tr> <? $i=0; while ($i < $num) { $first=mysql_result($result,$i,"first"); $last=mysql_result($result,$i,"last"); $phone=mysql_result($result,$i,"phone"); $mobile=mysql_result($result,$i,"mobile"); $fax=mysql_result($result,$i,"fax"); $email=mysql_result($result,$i,"email"); $web=mysql_result($result,$i,"web"); $id=mysql_result($result,$i,"id"); ?> <tr> <td><font face="Verdana" size="2"><? echo "$first"; ?></font></td> <td><font face="Verdana" size="2"><? echo "$last"; ?></font></td> <td><font face="Verdana" size="2"><? echo "$phone"; ?></font></td> <td><font face="Verdana" size="2">£<? echo "$mobile"; ?></font></td> <td><font face="Verdana" size="2">£<? echo "$fax"; ?></font></td> <td><font face="Verdana" size="2"><? echo "$email"; ?></font></td> <td><font face="Verdana" size="2"><? echo "$web"; ?></font></td> <td><font face="Verdana" size="2"><CENTER><a href="update.php?id=<? echo "$id"; ?>">Modify</a></font></CENTER></td> <td><font face="Verdana" size="2"><CENTER><a href="delete.php?id=<? echo "$id"; ?>">Delete</a></font></CENTER></td> </tr> <? ++$i; } echo "</table>"; ?> I am stuck and don't know how to add this small feature on. MANY THANKS!!!! Ian :D Link to comment https://forums.phpfreaks.com/topic/207177-how-do-i-reduce-a-mysql-table-quantity-by-1/ Share on other sites More sharing options...
Pikachu2000 Posted July 8, 2010 Share Posted July 8, 2010 UPDATE `table` SET `field` = `field` - 1 WHERE whatever_condition_is_met LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/207177-how-do-i-reduce-a-mysql-table-quantity-by-1/#findComment-1083249 Share on other sites More sharing options...
colleyboy Posted July 8, 2010 Author Share Posted July 8, 2010 so name a variable? i.e: $reduce = UPDATE `table` SET `field` = `field` - 1 WHERE whatever_condition_is_met LIMIT 1 then put <TD><A HREF="$reduce">Reduce</A></TD> I am confused. how would I go about doing it mate? Ian Link to comment https://forums.phpfreaks.com/topic/207177-how-do-i-reduce-a-mysql-table-quantity-by-1/#findComment-1083251 Share on other sites More sharing options...
Pikachu2000 Posted July 8, 2010 Share Posted July 8, 2010 No, but perhaps I read that wrong. Are you trying to update the database to indicate the stock is reduced by 1, or just display it that way on the page? Link to comment https://forums.phpfreaks.com/topic/207177-how-do-i-reduce-a-mysql-table-quantity-by-1/#findComment-1083254 Share on other sites More sharing options...
colleyboy Posted July 8, 2010 Author Share Posted July 8, 2010 At the moment I have a page which shows a table with the following-ish: Barcode | Description | Location | Price | Price Retail | Quantity | Dealer | Modify | Delete | =============================================================== $Barcode | $Description | $Location | $Price | $Price Retail | $Quantity | $Dealer | MODIFY | DELETE | This then loops results of the table downwards. I want to add a column on the right for "Reduce Quantity". Each row currently has 2 hyperlinks "modify" and "delete". I want to add one for "reduce quantity". When the hyperlinks selected I want it to reduce the integer in "$quantity" by 1. How would I go about this pikachu2000? I do not know Ian Link to comment https://forums.phpfreaks.com/topic/207177-how-do-i-reduce-a-mysql-table-quantity-by-1/#findComment-1083258 Share on other sites More sharing options...
Pikachu2000 Posted July 8, 2010 Share Posted July 8, 2010 You'll need another script to handle that request, and add a link to it in the script above. A couple questions you should consider: should the script ask the user for confirmation before reducing the quantity? Should the quantity be allowed to be set to a negative number (backorders, perhaps)? What needs to happen after the script runs? Return the user to the previous page, or . . . ? Side note: on line 3, the session_is_registered() function is deprecated, and should be if( !isset($_SESSION['myusername']) ) { Link to comment https://forums.phpfreaks.com/topic/207177-how-do-i-reduce-a-mysql-table-quantity-by-1/#findComment-1083271 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.