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
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.