billynastie Posted February 5, 2007 Share Posted February 5, 2007 Hi i am having a problem getting some information to update the correct way and could do with a few pointers. firstly i have a mysql table with the fields quantity and on order when i generate a purchase order the qty ordered goes to the on order field when i update what i want it to do is select from a from the words recieved then if recieved is selected take the amount from the field on order and add it to the field quantity is is possible and here is the update script which actually updates a field called paid_with with the text that is selected. function update1($field_names,$tablename,$id,$output) { //pre: $field_names and $field_data are pararell arrays and tablename and id are strings. //post: creates a query then executes it limites based on id. if($id=='') { echo "{$this->lang->didNotEnterID}"; exit(); } if(!($this->isValidData($field_data))) { echo "{$this->lang->invalidCharactor}"; exit(); } $query="UPDATE $tablename SET $field_names[0]=\"$field_data[0]\""; for($k=1;$k< count($field_names);$k++) { $query.=', '."$field_names[$k]=\"$field_data[$k]\""; } $sales_items_table=$this->tblprefix.'sales_items'; if($output) { $query.=" WHERE id=\"$id\""; } else { $query.=" WHERE sale_id=\"$id\""; } mysql_query($query,$this->conn); if($output) { echo "<center><b>{$this->lang->successfullyUpdated} $tablename</b></center><br>"; echo "<center><table width=350 cellspacing=$this->cellspacing cellpadding=$this->cellpadding bgcolor=$this->table_bgcolor style=\"border: $this->border_style $this->border_color $this->border_width px\"> <tr bgcolor=$this->header_rowcolor> <th align='left'><font color='$this->header_text_color' face='$this->headerfont_face' size='$this->headerfont_size'>{$this->lang->field}</th></font> <th align='left'><font color='$this->header_text_color' face='$this->headerfont_face' size='$this->headerfont_size'>{$this->lang->data}</th></font> </tr>"; for($k=0;$k<count($field_names);$k++) { //certain fields I do not want displayed. if($field_names[$k]!="password") { echo "<tr bgcolor=$this->rowcolor><td width='120'><font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$field_names[$k]". '</font></td>'."<td><font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$field_data[$k]</font></td></tr>\n"; } else { echo "<tr bgcolor=$this->rowcolor><td width='120'><font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$field_names[$k]". '</font></td>'."<td><font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>*******</font></td></tr>\n"; } } echo '</table></center>'; } } Link to comment https://forums.phpfreaks.com/topic/37131-update-function/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.