calculation in mysql query
Posted: Sun Aug 05, 2012 2:16 am
Hi there,
I want to insert value from calculation in mysql query. How to do that?
For example:
In the above example table name in mysql query will be derived from a post value of a html form. Value of respective column of mysql table will be derived from explode value.
My question is how to write proper sql query string so that variable name (like $table) and calculation ($value[$counter+1]) will be executed in the sql query?
(like "INSERT INTO".$table."(amount1,amount2).....")
Any help will be appreciated.
Thanks in advance
I want to insert value from calculation in mysql query. How to do that?
For example:
Code: Select all
$table = $Post['table'];
$array = (100,200,300,400,500);
$value = explode(',',$array);
$limit = count($value);
$counter = 1;
//........Connection string
while($counter<=$limit){
mysql_query("INSERT INTO $table (amount1, amount2) Values($value[$counter],$value[$counter+1])")
$counter=$counter+1;
}
My question is how to write proper sql query string so that variable name (like $table) and calculation ($value[$counter+1]) will be executed in the sql query?
(like "INSERT INTO".$table."(amount1,amount2).....")
Any help will be appreciated.
Thanks in advance