Update Row Value By Percentage

I need to be able to update a row in the database (price) by a percentage value which is entered either by typing into an input box or by up/down arrows.

I know I can update via a query directly by using

UPDATE table_name SET column_name=column_name*(100+percentage)/100

I just have no idea where to start with php.

Any tips, hints or tutorials you could point me to. A google and github search has just given me a headache :pensive:

Thanks

It is still an update. In the model for that property, do the math,

$value = 55;

function formula($val)
{
	return $val/100;
	
}

echo formula($value);

sorry due to work comments I have not been able to get back to this but lets get it on.

I have 2 tables which are tbl_temp_products and tbl_temp_categories and the fields as below (there are more fields but not relevant to this question)

tbl_temp_products contains colums called id and categories
eg.
id - row value 1
categories - row values - 100175, 100575 (this is how they are stored in this table)

tbl_temp_categories
eg.
categories_id - row value 100175
categories_name - row value Mugs

categories_id - row value 100575
categories_name - row value Souvenirs & Seaside

I presume I need to join the tables with a query to be able to update the price by percentage by category in tbl_temp_products

I have the following code which creates a dropdown with the categories from tbl_temp_categories

[code] <?php
$sql = “SELECT categories_id, categories_name FROM tbl_temp_categories”;

$result = $conn->query($sql);

echo "<select name='categories_name' class='form-control'>";
 while ($row = mysqli_fetch_array($result)) {
  echo "<option value='" . $row['categories_name'] . "'>" . $row['categories_name'] . "</option>";
 }
  echo "</select>";
?>
[/code]

Do I use a cross, inner, outer, left or right join as I am a bit confused on how to link the 2 tables.

I hope all the above made sense urgh

if you expect records that MUST have a corresponding set in both tables, use INNER JOIN. And read tutorials about the others.

Sponsor our Newsletter | Privacy Policy | Terms of Service