Jump to content

[SOLVED] Find the id im looking for


mike12255

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :)

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.