Eiolon Posted January 23, 2010 Share Posted January 23, 2010 When users click the refresh button, I want the records from the Access database to move to the MySQL database. It semi-working except I am only getting the first record from the Access database transferred over. Any ideas on how to get the other records? <?php $conn=odbc_connect('pcres','',''); $sql="SELECT PC_Id, Stop_Time FROM usage"; $rs=odbc_exec($conn,$sql); require_once('includes/mysql.php'); $pc = odbc_result($rs,"PC_Id"); $stop = odbc_result($rs,"Stop_Time"); $query_users = "SELECT pc, stop FROM pcres ORDER BY stop ASC"; $users = mysql_query($query_users) OR die ('Cannot retrieve a list of current users.'); if (isset($_POST['refresh'])) { $delete_old = "DELETE FROM pcres"; $result_old = mysql_query($delete_old) OR die ('Could not delete old data.'); if ($delete_old) { $insert = "INSERT INTO pcres (pc, stop) VALUES ('$pc','$stop')"; $result = mysql_query($insert) OR die ('Could not insert into database.'); if ($insert) { header('Location: index.php'); exit; } } } ?> <form id="add" name="add" method="post" action=""><input type="submit" name="refresh" id="button" value="REFRESH" /></form> <table class="data" border="1"> <tr> <th><div align="left">PC</div></th> <th><div align="left">Stop Time</div></th> </tr> <?php do { ?> <tr onmouseover="this.bgColor='#EBFAFF';" onmouseout="this.bgColor='#FFFFFF';"> <td><?php echo $row_users['pc']; ?></td> <td><?php echo $row_users['stop']; ?></td> </tr> <?php } while ($row_users = mysql_fetch_assoc($users)); ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/189569-transferring-records-from-access-to-mysql-via-php/ Share on other sites More sharing options...
Eiolon Posted January 25, 2010 Author Share Posted January 25, 2010 bump, anyone? Quote Link to comment https://forums.phpfreaks.com/topic/189569-transferring-records-from-access-to-mysql-via-php/#findComment-1001583 Share on other sites More sharing options...
premiso Posted January 25, 2010 Share Posted January 25, 2010 You need to loop the data: http://php.net/manual/en/function.odbc-fetch-array.php while( $myRow = odbc_fetch_array( $rs ) ) { $accessRows[] = $myRow; } Then you will have an array of the results and can use foreach to loop through them and do what you will with them (or you can add that logic inside the while.) Quote Link to comment https://forums.phpfreaks.com/topic/189569-transferring-records-from-access-to-mysql-via-php/#findComment-1001585 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.