Forum Moderators: coopster

Message Too Old, No Replies

how to open max id with php code for update?

how to open max id with php code for update?

         

shams

2:27 am on May 20, 2006 (gmt 0)

10+ Year Member



hi,
there is mysql table for the partients, each patient has multiple entries with the deferent id's (auto_incremetn), this php script will open the max(id) for update but this opens all the entries, any help please?
<html>
<body background="images/g13ice03.gif">
<b>
<?php
$id=$_POST['id'];
$name=$_POST['name'];
$fatherName=$_POST['fatherName'];
mysql_connect("localhost","root");
mysql_select_db("mydb");

$query=" SELECT * FROM register WHERE id='$id' or name='$name' and fatherN='$fatherName' and WHERE id = 'MAX(id)'";
$result=mysql_query($query) or die(mysql_error());
$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {

$dateReg=mysql_result($result,$i,"dateReg");
$name=mysql_result($result,$i,"name");
$fatherN=mysql_result($result,$i,"fatherN");
$sex=mysql_result($result,$i,"sex");
$age=mysql_result($result,$i,"age");
$address=mysql_result($result,$i,"address");
$phone=mysql_result($result,$i,"phone");
$dateAttStar=mysql_result($result,$i,"dateAttStar");
$attCat=mysql_result($result,$i,"attCat");
$diseaseClass=mysql_result($result,$i,"diseaseClass");
$site=mysql_result($result,$i,"site");
$type=mysql_result($result,$i,"type");
$weight0=mysql_result($result,$i,"weight0");
$sp0=mysql_result($result,$i,"weight0");
$sp0Date=mysql_result($result,$i,"sp0Date");
$cs1=mysql_result($result,$i,"cs1");
$dateStop=mysql_result($result,$i,"dateStop");
$patientIs=mysql_result($result,$i,"patientIs");
$remarks=mysql_result($result,$i,"remarks");
?>

<form action="updatedRegister.php" method="post">
<input type="hidden" name="ud_id" value="<? echo $id;?>">
Date Of Registration:<input type="text" name="ud_dateReg" value="<? echo $dateReg;?>"><br>
Name: <input type="text" name="ud_name" value="<? echo $name;?>"><br>
Father Name: <input type="text" name="ud_fatherN" value="<? echo $fatherN;?>"><br>
Sex: <input type="text" name="ud_sex" value="<? echo $sex;?>"><br>
Age: <input type="text" name="ud_age" value="<? echo $age;?>"><br>
Address: <input type="text" name="ud_address" value="<? echo $address;?>"><br>
Phone: <input type="text" name="ud_phone" value="<? echo $phone;?>"><br>
Date ATT Started: <input type="text" name="ud_dateAttStar" value="<? echo $dateAttStar;?>"><br>
ATT Catagory: <input type="text" name="ud_attCat" value="<? echo $attCat;?>"><br>
Disease Classifcation: <input type="text" name="ud_diseaseClass" value="<? echo $diseaseClass;?>"><br>
Site OF Disease: <input type="text" name="ud_site" value="<? echo $siet;?>"><br>
Type Of Patient: <input type="text" name="ud_type" value="<? echo $type;?>"><br>
First Weight: <input type="text" name="ud_weight0" value="<? echo $weight0;?>"><br>
First Sputum Result: <input type="text" name="ud_sp0" value="<? echo $sp0;?>"><br>
First Sputum Date: <input type="text" name="ud_sp0Date" value="<? echo $sp0Date;?>"><br>
Sputum Lab NO: <input type="text" name="ud_sp0Lab" value="<? echo $sp0Lab;?>"><br>
First C/S Sensitive Drugs: <input type="text" name="ud_cs1" value="<? echo $cs1;?>"><br>
Date ATT Stopped: <input type="text" name="ud_dateStop" value="<? echo $dateStop;?>"><br>
Patient IS: <input type="text" name="ud_patientIs" value="<? echo $patientIs;?>"><br>
Remarks: <input type="text" name="ud_remarks" value="<? echo $remarks;?>"><br>
</b><br>
<input type="Submit" value="Update">
<input type="Reset">
<input type="button" value="Cancel" onCLICK="window.location='index.html'">
</form>
<?php
++$i;
}
?>
</b>
</body>
</html>

eelixduppy

3:51 am on May 20, 2006 (gmt 0)



Try changing your query to the following:
$query=" SELECT * FROM register WHERE ((id='$id') or (name='$name')) and (fatherN='$fatherName' and id = 'MAX(id))'";

I'm not sure this is going to work as you want, but it's worth a try.

shams

10:32 am on May 20, 2006 (gmt 0)

10+ Year Member



thanks for reply, the query doesn't work at all, any one else can solve this proble please?

dreamcatcher

11:13 am on May 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



shams,

Are you trying to update the latest entry? Not really sure what you want to do.

$query=" SELECT * FROM register WHERE ((id='$id') OR (name='$name')) AND (fatherN='$fatherName') ORDER BY id DESC LIMIT 1");

Does that do what you want?

dc

shams

11:40 am on May 20, 2006 (gmt 0)

10+ Year Member



hi dreamcatcher,
thanks for reply, extactly i want to update the latest entry i tried your query like this but doesn't work:
$query=" SELECT * FROM register WHERE ((id='$id') OR (name='$name')) AND (fatherN='$fatherName') ORDER BY id DESC LIMIT 1)";
the ouput is just a blank page

dreamcatcher

11:57 am on May 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Strange. Try setting your error reporting level to E_ALL if you don`t already. This might throw some light on the error.

Anyway, the closing parenthesis is probably the problem:

$query=" SELECT * FROM register WHERE ((id='$id') OR (name='$name')) AND (fatherN='$fatherName') ORDER BY id DESC LIMIT 1";

or simplify the query down:

$query="SELECT * FROM register WHERE name='$name' AND fatherN='$fatherName' ORDER BY id DESC LIMIT 1";

dc

shams

12:24 pm on May 20, 2006 (gmt 0)

10+ Year Member



thanks so much for your help, the last query work perfect.

dreamcatcher

12:27 pm on May 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Anytime shams.

Glad I could help.

dc