Hi there,
I want to insert value from calculation in mysql query. How to do that?
for example:
[php]$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;
}[/php]
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