knowram Posted June 22, 2007 Share Posted June 22, 2007 is there a what to do some thing like this $result = mysql_query("select * from Networkinfo where mNum 'is the highest' ") or die ("nope1"); I am trying to figure out a way to assign an increasing number to each entry that gets added to a table. So my thinking is that i have to know the highest number that is currently in the table and then just add 1. or is there another way? Thanks for the help Link to comment https://forums.phpfreaks.com/topic/56760-help-with-select-statment/ Share on other sites More sharing options...
chigley Posted June 22, 2007 Share Posted June 22, 2007 [pre]SELECT * FROM Networkinfo ORDER BY mNUM ASC LIMIT 1[/pre] You may want to look into an auto-incrementing field though Link to comment https://forums.phpfreaks.com/topic/56760-help-with-select-statment/#findComment-280311 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 your primary key can be auto_incremented Link to comment https://forums.phpfreaks.com/topic/56760-help-with-select-statment/#findComment-280313 Share on other sites More sharing options...
knowram Posted June 22, 2007 Author Share Posted June 22, 2007 an auto increasing key would be cool is the a mysql or mssql feature or both? Link to comment https://forums.phpfreaks.com/topic/56760-help-with-select-statment/#findComment-280318 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 If you use phpmyadmin when making tables you can assign it, but note it must be you primary key can we see your table structure to help you better? Link to comment https://forums.phpfreaks.com/topic/56760-help-with-select-statment/#findComment-280320 Share on other sites More sharing options...
knowram Posted June 22, 2007 Author Share Posted June 22, 2007 sure what would be the best way to show you the table structure? Link to comment https://forums.phpfreaks.com/topic/56760-help-with-select-statment/#findComment-280323 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 your fields there types and the primary key Link to comment https://forums.phpfreaks.com/topic/56760-help-with-select-statment/#findComment-280326 Share on other sites More sharing options...
knowram Posted June 22, 2007 Author Share Posted June 22, 2007 the first table only has 2 fields right now they are set up like this mNum varchar(255) mCompany varchar(255) i am using phpmyadmin however I am really new to it. I don't know much more then adding adding fields to tables and tables to databases and adding databases. I have been mostly using either varchar or me mediumtext for the field types. And i know nothing about keys yet. however I am a fast learner Link to comment https://forums.phpfreaks.com/topic/56760-help-with-select-statment/#findComment-280332 Share on other sites More sharing options...
knowram Posted June 22, 2007 Author Share Posted June 22, 2007 I think i was able to figure out the auto increasing feature however i am still not clear what establishing the field as a key allows you to do. Link to comment https://forums.phpfreaks.com/topic/56760-help-with-select-statment/#findComment-280356 Share on other sites More sharing options...
knowram Posted June 22, 2007 Author Share Posted June 22, 2007 ok now that i have done that let me explain what i am trying to do. I have to tables table 1 (aMember) mNum mCompany table 2 (aOffice) mNum oNum Office Address Domain Net_Connection I have several member company's (mCompany) and each of those has several Offices. if I add a new office to a member company i just add the info to the aOffice table using putting the mNum from the member company entry in the aMember table. no big deal. But if I am adding a new Office that is part of a new member company I want to add the member company name to the aMember table which is now getting a mNum assigned automatically. How do I know what that mNum is so I can use it when adding the office info to the aOffice table? Hope that makes sense. Link to comment https://forums.phpfreaks.com/topic/56760-help-with-select-statment/#findComment-280464 Share on other sites More sharing options...
knowram Posted June 22, 2007 Author Share Posted June 22, 2007 or is there a way to like the two? Link to comment https://forums.phpfreaks.com/topic/56760-help-with-select-statment/#findComment-280466 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 whats linking your two tables? Link to comment https://forums.phpfreaks.com/topic/56760-help-with-select-statment/#findComment-280471 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 if you are using mNum as your connection between the 2 i'd suggest adding a primary key field called ID to both tables to give each row some better uniqueness. Link to comment https://forums.phpfreaks.com/topic/56760-help-with-select-statment/#findComment-280472 Share on other sites More sharing options...
knowram Posted June 22, 2007 Author Share Posted June 22, 2007 as far as i know nothing i don't know how to do that yet i just use join in my select statements to link them Link to comment https://forums.phpfreaks.com/topic/56760-help-with-select-statment/#findComment-280473 Share on other sites More sharing options...
knowram Posted June 22, 2007 Author Share Posted June 22, 2007 i have a field called oNum in the aOffice table for it now auto increasing key Link to comment https://forums.phpfreaks.com/topic/56760-help-with-select-statment/#findComment-280475 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 thats fine, i generally just make a field called ID as my primary key and auto increment it for any table just for ease of use. Then i link between tables with my users names. try the function $idnum=mysql_insert_id(); where it will give you the autokey num of the last query of insertion Link to comment https://forums.phpfreaks.com/topic/56760-help-with-select-statment/#findComment-280479 Share on other sites More sharing options...
knowram Posted June 22, 2007 Author Share Posted June 22, 2007 ok i will give that a try and see what it dose Link to comment https://forums.phpfreaks.com/topic/56760-help-with-select-statment/#findComment-280484 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.