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