# Need help on writing looping

**URL:** <https://forum.kirupa.com/t/need-help-on-writing-looping/324716>\
**Category:** programming\
**Created:** [September 5, 2011, 10:02am UTC](https://forum.kirupa.com/t/need-help-on-writing-looping/324716 "2011-09-05T10:02:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Fan](https://avatars.discourse-cdn.com/v4/letter/p/7ea924/32.png) [@Paul\_Fan](https://forum.kirupa.com/u/Paul_Fan)\
**Post date:** [September 5, 2011, 10:02am UTC](https://forum.kirupa.com/t/need-help-on-writing-looping/324716/1 "2011-09-05T10:02:13Z")

</div>

Hello all

I am a php new bibe, could you please help where I should a the loop at below code?  
this is a PHP that delete all data from a MYSQL and then copy the table date from MS SQL(master) to mysql again. I wrote a .bat file to run this in scheldure under windows machine.

status now: the program can delete the data inside the table  
it can copy data from MSSQL to MYSQL, but only one record, copy…

how to keep it loop and keep adding rows with all the data?

\<?php  
require\_once( “config.php” );  
//require\_once( “\_\_function.php” );  
$conn\_nmfs = odbc\_connect( DB\_NMFS\_ODBC,  
DB\_NMFS\_USERNAME,  
DB\_NMFS\_PASSWORD );  
$conn = new mysqli( DB\_MIS\_SERVER ,  
DB\_MIS\_SERVER\_USERNAME,  
DB\_MIS\_SERVER\_PASSWORD,  
DB\_MIS\_DATABASE,  
DB\_MIS\_SERVER\_PORT );

$mysql=“DELETE FROM interface\_cash\_payment\_chart”;  
$stmt = $conn-\>prepare( $mysql );  
$stmt-\>execute();  
//finish delete all data in table at MYSQL  
//Insert data from MS SQL to MYSQL  
$str = "INSERT INTO interface\_cash\_payment\_chart set  
AREA\_CODE = ?,  
BLDG\_CODE = ?,  
LONG\_DATE = ?,  
DATE\_YEAR = ?,  
DATE\_MONTH = ?,  
DATE\_DAY = ?,  
TRX\_COUNT = ?,  
TRX\_AMOUNT = ? ";  
$stmt\_in = $conn-\>prepare($str);  
$mssql=“SELECT \* FROM mis\_interface\_cash\_payment\_chart”;  
$result=odbc\_exec($conn\_nmfs, $mssql);

$total\_records = odbc\_fetch\_row($result);  
//for($i = 0; $i \< $total\_records; $i++){  
while($row=odbc\_fetch\_row($result))  
{  
$AREA\_CODE = odbc\_result($result,“AREA\_CODE”);  
$BLDG\_CODE = odbc\_result($result,“BLDG\_CODE”);  
$LONG\_DATE = odbc\_result($result,“LONG\_DATE”);  
$DATE\_YEAR = odbc\_result($result,“DATE\_YEAR”);  
$DATE\_MONTH = odbc\_result($result,“DATE\_MONTH”);  
$DATE\_DAY = odbc\_result($result,“DATE\_DAY”);  
$TRX\_COUNT = odbc\_result($result,“TRX\_COUNT”);  
$TRX\_AMOUNT = odbc\_result($result,“TRX\_AMOUNT”);

$stmt\_in-\>bind\_param(“ssssssss”,  
$AREA\_CODE,  
$BLDG\_CODE,  
$LONG\_DATE,  
$DATE\_YEAR,  
$DATE\_MONTH,  
$DATE\_DAY,  
$TRX\_COUNT,  
$TRX\_AMOUNT  
);  
$stmt\_in-\>execute();  
}

?\>
