0
$rowdata = mysql_query("DESC ".$table_name."");
$names = array();
while($row = mysql_fetch_array($rowdata)) 
{
    $names[] = $row['Field'];
    $var_names[] = $row['Field'];
}

$qu1="\$qu=\"update ".$table_name." set ";
$qu1.="".implode('=\'".'."$"."jj.\"'".",", $names)."='Y'\";"."";
$qu3="'\".$".implode(".\"', '\".$", $var_names).".\"')\";";
echo $qu1;

OUTPUT:

update inmines_contractor set contractor_id='".$contractor_id."', contractor_name='".$contractor_name."'

I want echo/print Update Query Values Like following way update inmines_contractor set contractor_id='".$contractor_id."', contractor_name='".$contractor_name."'

VIJAY P
  • 1,363
  • 1
  • 12
  • 14
  • 1
    [Please, don't use mysql_* functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) in new code. They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [red box](http://uk.php.net/manual/en/function.mysql-connect.php)? Learn about [_prepared statements_](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide which. – TNK Mar 13 '13 at 14:32

2 Answers2

0
<?php
while($row = mysql_fetch_array($rowdata)) 
{
    $names[] = $row['Field'];
    $var_names[] = $$row['Field'];
}

$qu1="insert into ".$table_name."";
$qu1.=" (".implode(', ', $names)."";
$qu1.=" ) values ( "."'".implode('\', \'', $var_names)."' )"."";
?>

Try this. This will help.

Rohit Subedi
  • 560
  • 3
  • 13
0
$var_names[0] = "test";$var_names[1]= "test2";$qu1 = "";

$qu1.=" ) values ( '\".$".implode(".\"', '\".$", $var_names).".\"')";

echo $qu1;

) values ( ' ".$test." ',' ".$test2." ')

karmafunk
  • 1,453
  • 12
  • 20
  • You should take the spaces out between " & ' as this would save the values with a space either side. I put them in for ease of viewing. – karmafunk Mar 14 '13 at 14:12