mike12255 Posted September 19, 2009 Share Posted September 19, 2009 so i've setup my database layout below. As you can see pages and users both have the field bid this refers to the id in basic_info. I thought this would be a great idea so i could use one database for all my clients however i ran into a problem. im not sure how to tell php which id it should query into bid. I use an automated script to insert all the info into my database and before i had a seperate db for every client. So say i have 323 clients in my db and i got to add a new one so there will be 324 how can i tell php to find out that bid should equal 324 and query it in with the new entery? table feilds basic_info id cleint cleint_email website website_info Pages id bid name info usersidbidusernamepassword Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 19, 2009 Share Posted September 19, 2009 sounds more like a sql question. You could count the total number of entries currently in a table, add it by 1 and you would have the next avail user id or You could make sure the id is incremental and find the most recent id, then add it by 1. Quote Link to comment Share on other sites More sharing options...
mike12255 Posted September 19, 2009 Author Share Posted September 19, 2009 i do have id set to auto increment for each table, is there a function to find the highest one? Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 19, 2009 Share Posted September 19, 2009 The problem with finding the next id before allocating it is... it can be allocated by another user before being used by first user. Best method is to add to the first table, creating the next auto inc id, then retrieve that new id and use it for the remainder of sql queries. Quote Link to comment Share on other sites More sharing options...
mike12255 Posted September 19, 2009 Author Share Posted September 19, 2009 i think i do that, on the one page i query the basic_info table, and then on the next page after that i query info into the other two tables Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 19, 2009 Share Posted September 19, 2009 Is this the process you want? [*]Insert new entry into basic_info [*]Get id of new entry [*]Insert into pages, users with new id Am unclear on what the question is now. Quote Link to comment Share on other sites More sharing options...
mike12255 Posted September 19, 2009 Author Share Posted September 19, 2009 yeah thats exactly what i need to do Quote Link to comment Share on other sites More sharing options...
knsito Posted September 19, 2009 Share Posted September 19, 2009 http://us3.php.net/manual/en/function.mysql-insert-id.php The PHP Manual is well documented and a great resource. More people on this forum should use it.. It will solve many of these questions... Is this the process you want? [*]Insert new entry into basic_info [*]Get id of new entry [*]Insert into pages, users with new id Am unclear on what the question is now. Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 19, 2009 Share Posted September 19, 2009 I didn't realise he wanted the actual code typed for him. I thought it was more the process he was wanting to get. knsito is right, between php and mysql manual, the process you are wanting to code is documented there. Quote Link to comment Share on other sites More sharing options...
mike12255 Posted September 19, 2009 Author Share Posted September 19, 2009 i was more less looking for the function name rather then having it typed for me... Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 19, 2009 Share Posted September 19, 2009 No probs, as mentioned though, I would hesitate at finding the next value that may or may not be added to auto inc. Adding to basic_info first, then retrieving the actual id that was given is safest way or you risk the id being used by another user. If you are the only user who can access it, then is different mysql > select LAST_INSERT_ID() this will change for each user who has a connection though. Still say to add them, then see what id they ACTUALLY have Good luck 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.