MySQL Forums
Forum List  »  PHP

html,mysql,php copy data from one db to another
Posted by: brian liddle
Date: June 01, 2012 04:51PM

i have 2 db's, one that updates and one that i need to update with the new information from the other.
i create a connection query the first database and put the data from the table i need in the variable 'MainResult'. I need to take that data and if the row already exists in my second table, update the corresponding row and if not, insert a new row with the data. all this is supposed to be viewable in an html table. please help.


below is the chunk of my code after i connect to the first, query it, and then connect to the second.
CODE:

echo "<table border='1'>
<tr>
<th>JobNumber</th>
<th>Method</th>
<th>RuleName</th>
<th>ClinicID</th>
<th>ClinicName</th>
<th>DictatorID</th>
<th>AppointmentDate</th>
<th>AppointmentTime</th>
<th>JobType</th>
<th>ContextName</th>
<th>MRN</th>
<th>FirstName</th>
<th>LastName</th>
<th>DOB</th>
<th>Custom1</th>
<th>Custom6</th>
<th>Custom12</th>
</tr>";

while($row = mysql_fetch_array($MainResult))
{
$column1=$row['JobNumber']
$column2=$row['Method']
$column3=$row['RuleName']
$column4=$row['ClinicID']
$column5=$row['ClinicName']
$column6=$row['DictatorID']
$column7=$row['AppointmentDate']
$column8=$row['AppointmentTime']
$column9=$row['JobType']
$column10=$row['ContextName']
$column11=$row['MRN']
$column12=$row['FirstName']
$column13=$row['LastName']
$column14=$row['DOB']
$column15=$row['Custom1']
$column16=$row['Custom6']
$column17=$row['Custom12']



mysql_query("UPDATE JTD SET Method="$column2",
RuleName="$column3",
ClinicID="$column4",
ClinicName="$column5",
DictatorID="$column6",
AppointmentDate="$column7",
AppointmentTime="$column8",
JobType="$column9",
ContextName="$column10",
MRN="$column11",
FirstName="$column12",
LastName="$column13",
DOB="$column14",
Custom1="$column15",
Custom6="$column16",
Custom12="$column17"
WHERE JubNumber="$column1"
IF @@ROWCOUNT=0
INSERT INTO JTD VALUES ("$column1","
$column2","
$column3","
$column4","
$column5","
$column6","
$column7","
$column8","
$column9","
$column10","
$column11","
$column12","
$column13","
$column14","
$column15","
$column16","
$column17");")
}


$MirrorResult = mysql_query("SELECT * from JTD")

while($row = mysql_fetch_array($MirrorResult))
{

echo "<tr>";
echo "<td> . $row['JobNumber'] . </td>";
echo "<td> . $row['Method'] . </td>";
echo "<td> . $row['RuleName'] . </td>";
echo "<td> . $row['ClinicID'] . </td>";
echo "<td> . $row['ClinicName'] . </td>";
echo "<td> . $row['DictatorID'] . </td>";
echo "<td> . $row['AppointmentDate'] . </td>";
echo "<td> . $row['AppointmentTime'] . </td>";
echo "<td> . $row['JobType'] . </td>";
echo "<td> . $row['ContextName'] . </td>";
echo "<td> . $row['MRN'] . </td>";
echo "<td> . $row['FirstName'] . </td>";
echo "<td> . $row['LastName'] . </td>";
echo "<td> . $row['DOB'] . </td>";
echo "<td> . $row['Custom1'] . </td>";
echo "<td> . $row['Custom6'] . </td>";
echo "<td> . $row['Custom12'] . </td>";
echo "</tr>";
}
echo "</table>";

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.