Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-24-2007, 03:29 AM   PM User | #1
tanhaha_how
Regular Coder

 
Join Date: Feb 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
tanhaha_how is an unknown quantity at this point
delete problem

hi, i ahve some query problem....below is my code.
Code:
<?php
	include 'connStr.php';
	include 'datediff.php';

$query = "SELECT * FROM tblpatient";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
while ($row = mysql_fetch_array($result)){


$query2 = "Select * from tbloverdue";
$result2 = mysql_query($query2);
$row2 = mysql_fetch_assoc($result2);

$TD = $row["Treatment_Date"];
$patientID = $row["Patient_ID"];
$overdueID = $row2["Patient_ID"];

$diff = datediff("$TD","now","m");

if (($row["Email"]) == ""){
$row["Email"] = "NO";}

if ($diff > 5 && $patientID != $overdueID){

	$query1 = "Insert into tbloverdue(Patient_ID, Name, Treatment_Date, Email)values('".$row["Patient_ID"]."', '".$row["Name"]."', '".$row["Treatment_Date"]."', '".$row["Email"]."')";
	$result1 = mysql_query($query1);
	
}
}

	$query3 = "DELETE o.* FROM tbloverdue as o, (SELECT MAX(Overdue_ID) AS dupid, COUNT(Patient_ID) AS dupcnt FROM tbloverdue GROUP BY Patient_ID, HAVING dupcnt>1) AS dups WHERE o.Patient_ID = dups.dupcnt";
	$result3 = mysql_query($query3);

	mysql_query("COMMIT");

	echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">";
	echo "<meta http-equiv=\"REFRESH\" content=\"0; URL=overdue.php\">";

?>
the INSERT query works properly...but the DELETE query cannot work at all...actually the DELETE query is to delete the duplicate records.but dunno y it cant works at all...
can somebody help me pls???????
tanhaha_how is offline   Reply With Quote
Old 02-24-2007, 03:46 AM   PM User | #2
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
you can't do a select on a table you plan to delete rows from.

note you should look into using mysql_error() in php as it would print the actual error message out to you and you would have seen that info.
guelphdad is offline   Reply With Quote
Old 02-24-2007, 05:27 AM   PM User | #3
tanhaha_how
Regular Coder

 
Join Date: Feb 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
tanhaha_how is an unknown quantity at this point
did u mean the query below is not correct???

Code:
$query3 = "DELETE o.* FROM tbloverdue as o, (SELECT MAX(Overdue_ID) AS dupid, COUNT(Patient_ID) AS dupcnt FROM tbloverdue GROUP BY Patient_ID, HAVING dupcnt>1) AS dups WHERE o.Patient_ID = dups.dupcnt";
but how to write a query to delete duplicate data???
tanhaha_how is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:04 AM.


Advertisement
Log in to turn off these ads.