rsammy Posted March 8, 2007 Share Posted March 8, 2007 this is my query. how do i get the last row in this? $selectadmissionquery=("SELECT pat_id, admit_status, admit_loc, admit_date, discharge_date, admit_encounter FROM admission WHERE (pat_id = '$pat_id') ORDER BY admit_date ASC"); $resultselectadmissionquery=mysql_query($selectadmissionquery); if (! $resultselectadmissionquery) { $error= "Error 333b"; } how do i get the admit_date of the last record in the above query? Quote Link to comment https://forums.phpfreaks.com/topic/41835-solved-last-row-in-array-or-record/ Share on other sites More sharing options...
hitman6003 Posted March 8, 2007 Share Posted March 8, 2007 SELECT pat_id, admit_status, admit_loc, admit_date, discharge_date, admit_encounter FROM admission WHERE (pat_id = '$pat_id') ORDER BY admit_date DESC LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/41835-solved-last-row-in-array-or-record/#findComment-202887 Share on other sites More sharing options...
rsammy Posted March 8, 2007 Author Share Posted March 8, 2007 no no no. i need to execute a query to get all admit _dates for a patient. then again, i have another admission for the same patient that falls between the obtained dates. i need to check and see where this date would fit in. i need to compare it with each admit_date in the above query! thats my ultimate goal thanx for the quick reply. Quote Link to comment https://forums.phpfreaks.com/topic/41835-solved-last-row-in-array-or-record/#findComment-202889 Share on other sites More sharing options...
Barand Posted March 8, 2007 Share Posted March 8, 2007 You could do 2 queries, the first to find dates less than the new dat and the other to find those greater Quote Link to comment https://forums.phpfreaks.com/topic/41835-solved-last-row-in-array-or-record/#findComment-202899 Share on other sites More sharing options...
sasa Posted March 8, 2007 Share Posted March 8, 2007 try $last_admit_date = mysql_result($resultselectadmissionquery,mysql_num_rows($resultselectadmissionquery)-1,'admit_date'); Quote Link to comment https://forums.phpfreaks.com/topic/41835-solved-last-row-in-array-or-record/#findComment-202905 Share on other sites More sharing options...
Barand Posted March 8, 2007 Share Posted March 8, 2007 Shouldn't it be mysql_num_rows() - 1 Quote Link to comment https://forums.phpfreaks.com/topic/41835-solved-last-row-in-array-or-record/#findComment-202907 Share on other sites More sharing options...
rsammy Posted March 8, 2007 Author Share Posted March 8, 2007 say i have admit dates of 02/01/2007 at 4 15 pm, 02/01/2007 at 10 17 pm, 02/02/2007 at 10 18 pm, 02/03/2007 at 11 40 am, 02/04/2007 at 3 27 pm, 02/06/2007 at 3 28 pm and 02/08/2007 at 3 30 pm. these are the dates returned with my query in ascending order. now, i have another date 02/05/2007 at 12 30 pm that needs to be inserted into the table after 02/04/2007! how do i do this? this is should now become the sixth record in the chain. how is this possible? thanx for replying Quote Link to comment https://forums.phpfreaks.com/topic/41835-solved-last-row-in-array-or-record/#findComment-202915 Share on other sites More sharing options...
Barand Posted March 8, 2007 Share Posted March 8, 2007 You just insert the record as the next row in the table. I seem to be saying this a lot lately, but, the physical position of a record in a table is irrelevant Quote Link to comment https://forums.phpfreaks.com/topic/41835-solved-last-row-in-array-or-record/#findComment-202922 Share on other sites More sharing options...
rsammy Posted March 8, 2007 Author Share Posted March 8, 2007 no. this is relevant here. if i insert it as the last record in the table, then the system thinks its a new admission of the patient on a previous date. what i need here is that it should go and sit where it belongs to (date-wise). every record entered in this table is counted as an encounter. the doctor may suddenly remember he forgot that he visited this patient on that day and decide to enter it into the system. it shud not come be another entry after the patient has been released/discharged on 02/08/2007! Quote Link to comment https://forums.phpfreaks.com/topic/41835-solved-last-row-in-array-or-record/#findComment-202925 Share on other sites More sharing options...
Barand Posted March 8, 2007 Share Posted March 8, 2007 Use "ORDER BY date" in the query. If you want to keep your data physicaly ordered, forget about databases and use flat files. Quote Link to comment https://forums.phpfreaks.com/topic/41835-solved-last-row-in-array-or-record/#findComment-202929 Share on other sites More sharing options...
rsammy Posted March 8, 2007 Author Share Posted March 8, 2007 ??? help please? how do i do that? Quote Link to comment https://forums.phpfreaks.com/topic/41835-solved-last-row-in-array-or-record/#findComment-202933 Share on other sites More sharing options...
rsammy Posted March 8, 2007 Author Share Posted March 8, 2007 resolved Quote Link to comment https://forums.phpfreaks.com/topic/41835-solved-last-row-in-array-or-record/#findComment-202972 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.