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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 your primary key can be auto_incremented Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 whats linking your two tables? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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.