Jump to content

Multiple postgres database columns update


Broun

Recommended Posts

I have a couple of tables with different input column values. I am trying to update all the table at once but am failing. My problem looks to be my php skills. Please help!!!!!

I have this form code which returns the editable data:

$rows = pg_num_rows($result);
    for ($k = 0; $k < $rows; $k++)
   {
for ($j = 0; $j < $i; $j++) {
       $fieldname = pg_field_name($res, $j);
$retu = pg_fetch_result($result,$k,$j) ;
  if ($fieldname == "gid")
echo '<td class="hr">'. htmlspecialchars($retu) ;
else
echo '<td class="hr"><input name="'.$fieldname.$k. '" type="text" value="'. $retu .'">';

And this is the code for updating the database table:

$norows = pg_num_rows($res);
$i = pg_num_fields($res);
if(isset($_POST['update']))
{
$r = 0;
while ($r < $norows)
{

$sql1 = 'UPDATE'." $editable SET ";
for ($j = 0; $j < $i; $j++)
{ $type .= pg_field_type($res, $j);

  $fieldname = pg_field_name($res, $j);

if ($j==$i-1 )
{

$sql1 .= " $fieldname =  ".@$_POST.'[ \''. $fieldname.$r.'\' ] ';
  }
  else
{
  $sql1 .= " $fieldname = ".@$_POST.'[ \''. $fieldname.$r.'\' ] '.', ' ;
}
}
$s =  ($r+1) ;
$sql1 .= "WHERE gid=$s".'; ';
//$result1= pg_query($conn,$sql1);
echo "$sql1";
++$r;
}
}
else

But then i get this output!

UPDATE material_parameters SET gid = Array[ 'gid0' ] , name = Array[ 'name0' ] , manning = Array[ 'manning0' ] , eqrough = Array[ 'eqrough0' ] , hazenwilliam = Array[ 'hazenwilliam0' ] , darcyweisbach = Array[ 'darcyweisbach0' ] WHERE gid=1; etc etc

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.