TRI0N Posted March 26, 2008 Share Posted March 26, 2008 Okay here is the gig. I have a Event Number that looks like this. CU-12345678901-0001 Breakdown CU (Company ID) - 1234567890 (Client ID) - 0001 (Event ID) Senerio: CU-1234567890-0012 is the hight event by this client. So then next added event by this client will be CU-1234567890-0013. At this time I have the Event ID as whole (CU-1234567890-0001 and I search the Event Table via Client ID which is CU-1234567890 and want it to look for the highes Event ID. In the Even Table I have cells that store just the trailing Event ID (0001) and the Client ID (CU-1234567890). Now I search for all records for that client. Now what I want to determin is the highest number trailing Event ID number. The rest is obvious that I want to increase this number by 1 for a new event which I have that part. Any help on how to determine the highest Trailing Event ID number would be Excellent. Thanks ahead of time. Link to comment https://forums.phpfreaks.com/topic/97900-find-highest-number/ Share on other sites More sharing options...
soycharliente Posted March 26, 2008 Share Posted March 26, 2008 MAX() Link to comment https://forums.phpfreaks.com/topic/97900-find-highest-number/#findComment-500889 Share on other sites More sharing options...
TRI0N Posted March 26, 2008 Author Share Posted March 26, 2008 Okay lets see I figured it would be max but I'm not sure where to put this in order to determin the MAX(). Let me attempt a connect code: // Database Connection mysql_connect("$dbhost","$dbuser","$dbpasswd") ; // Database Selection mysql_select_db("$dbname") ; // Check Client in Events Database $result50 = mysql_query("select distinct * from events WHERE client_id = '$client_id'") ; while($row = mysql_fetch_row($result50)) { $event_tail = $row[4] ; } $event_tail_max = MAX($event_tail) ; $event_tail = $event_tail_max + 1 ; Hot, Warm, Cold? Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/97900-find-highest-number/#findComment-500894 Share on other sites More sharing options...
soycharliente Posted March 26, 2008 Share Posted March 26, 2008 I was using the MySQL function. You'd put it directly inside the query. But now that I think about it, that may not work since you've got letters and numbers inside the client ID. Link to comment https://forums.phpfreaks.com/topic/97900-find-highest-number/#findComment-500911 Share on other sites More sharing options...
TRI0N Posted March 26, 2008 Author Share Posted March 26, 2008 No you are correct. Can you give me an example of using that in the Query.. row 4 only cotains the trailing number for the complete event ID. But the script I wrote above does work however it does not return the value in whole. 0001 is returned as 1. Not that this is a problem since I can format this number no doubt.. However it would be nice to see a query example. Link to comment https://forums.phpfreaks.com/topic/97900-find-highest-number/#findComment-500916 Share on other sites More sharing options...
TRI0N Posted March 26, 2008 Author Share Posted March 26, 2008 Okay this sucks.. I'm going nuts trying to use Max() in a query. $result50 = mysql_query("SELECT MAX(event_tail) FROM events WHERE client_id = '$client_id'") ; This isn't doing the trick and I've tried: $result50 = mysql_query("SELECT * FROM events WHERE client_id = '$client_id' AND MAX(event_tail)") ; Link to comment https://forums.phpfreaks.com/topic/97900-find-highest-number/#findComment-500976 Share on other sites More sharing options...
soycharliente Posted March 26, 2008 Share Posted March 26, 2008 What is the data type of event_tail? Link to comment https://forums.phpfreaks.com/topic/97900-find-highest-number/#findComment-500992 Share on other sites More sharing options...
TRI0N Posted March 26, 2008 Author Share Posted March 26, 2008 The date type is INT.. The following does the trick I need to do though.. mysql_query("SELECT * FROM events WHERE client_id = '$client_id' ORDER BY event_tail DESC LIMIT 1") ; Link to comment https://forums.phpfreaks.com/topic/97900-find-highest-number/#findComment-500994 Share on other sites More sharing options...
soycharliente Posted March 26, 2008 Share Posted March 26, 2008 That was my next suggestion if you couldn't get MAX to work. I'm sure it does the same thing in effect, just without having to type so much. Link to comment https://forums.phpfreaks.com/topic/97900-find-highest-number/#findComment-500997 Share on other sites More sharing options...
kevincro Posted March 26, 2008 Share Posted March 26, 2008 $result50 = mysql_query("SELECT MAX(event_tail) FROM events WHERE client_id = '$client_id'") ; $row50 = mysql_fetch_assoc($result50); $a= $row50['MAX(event_tail)']; $a should now contain the value you are looking for Link to comment https://forums.phpfreaks.com/topic/97900-find-highest-number/#findComment-501012 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.