PHP-Multiple Update in msql using php

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Tue Feb 04, 2003 12:09 pm

Try this code:

Code: Select all

$temphandle=explode(",",$_POST["oldname"]);
$tempcount=count($temphandle);
$link=mysql_connect("$host","$user","$password");
mysql_select_db($dbname,$link);
for($a=0; $a < $tempcount; $a++)
{
   $test="select * from employlist where employlist.fname='".$temphandle[$a]."'";
   $display=mysql_query($test,$link);
   $row=mysql_num_rows($display);
   if($row<>0){
      $row=mysql_fetch_array($display);
      $htemp=explode(",",$row["projects"]);
      $hcnttemp=count($htemp);
      $tempvalue="";
      $del=0;
         for($cnt=0;$cnt < $hcnttemp; $cnt++){
            if($htemp[$cnt]!=$projname){
               if((abs($hcnttemp-$cnt-$del))<=2){
                  $tempvalue.=$htemp[$cnt];
               }else{
                  $tempvalue.=$htemp[$cnt].",";
               }
            }else{
               $del++;
            }
         }
      $Query = "Update employlist set employlist.projects='". $tempvalue."' where (employlist.fname='".$temphandle[$a]."')";
      $save=mysql_query($Query);
      if(!$save)
         print "did not save";
      }
      $display = null;
      $test=null;
      $row=null;
   }
}
mysql_close($link);
?>

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 2 guests

cron