Jump to content

update recordset one by one


inamul70

Recommended Posts

How to update table records one by one....

 

I have a table with five records .. I am getting values of month from another function..I would like to fill the values of month into the table.(like jan feb mar april may) respectively in the first row instead of Average.

 

my code is below

 

$insquery = "select * from reporttmp";

               

                $insresult = mysql_query($insquery, $link) or die("Error in sql sytax.");

 

                $fel=mysql_num_fields($insresult);

 

                $nro=mysql_num_rows($insresult);

               

                $i=1;

               

               

                if ($nro > 0)

               

                {

               

                    while ($i < $nro - 1) 

               

                    {

                   

                        $monname = getmonthname($fmonth);

                        $monname = $monname. " ". $fyear;

                       

                       

                       

                        $upquery = ("UPDATE reporttmp SET vdate ='$monname' where mysql_num_row($insresult)=$i");       

                        if(!mysql_query($upquery, $link))

                        die ("Mysql error ....<p>".mysql_error());           

                       

                        $fmonth = $fmonth + 1;

                       

                        $i = $i + 1;

                       

                    }

               

               

               

                }

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/249891-update-recordset-one-by-one/
Share on other sites

First: If this database will stay the same, that is only five rows, then I would make another column named something like myrow and give them numbers 1~5. So so you just have to:

$upquery = ("UPDATE reporttmp SET vdate ='$monname' where myrow = $i;

and $i is 1~5

 

Second $monname = getmonthname($fmonth);  getmonthname is not php.  And you do not show where $fmonth comes from.

 

It looks like $fmonth is a number. Do you want a number in vdate?

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.