inamul70 Posted October 27, 2011 Share Posted October 27, 2011 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] Quote Link to comment https://forums.phpfreaks.com/topic/249891-update-recordset-one-by-one/ Share on other sites More sharing options...
sunfighter Posted October 27, 2011 Share Posted October 27, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/249891-update-recordset-one-by-one/#findComment-1282794 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.