Closed Thread Icon

Topic awaiting preservation: PHP MYSQL database checking - help (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=22101" title="Pages that link to Topic awaiting preservation: PHP MYSQL database checking - help (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: PHP MYSQL database checking - help <span class="small">(Page 1 of 1)</span>\

 
kronk
Obsessive-Compulsive (I) Inmate

From:
Insane since: Jun 2004

posted posted 06-09-2004 02:27

is there a way to check an entry via a form with an entry in a database. I have a form which enters new data into a database and need to check to see if an entry already exists with the same id number. On the form i have child details and parent details, I need to check to see if parent id already exists, if yes, do not add parent details but continue with child details. If no, add both child and parent. I have the insert queries already but am stuck on this problem.

Should I put a radio button in the form which asks if this is a new parent???

Is there some mysql or php function that will check details for me???

Any help is appreciated.
Thanks

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 06-09-2004 02:56

There may be a better way, but you can jsut do a query on the relevant table, searching for the parent id. If a match is found, do a, if not, do b.

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 06-09-2004 06:18

Yeh a query would be the way i think, im not sure wiht msql coz i mostly use ms access databases, but if its an indexed column then this wouldnt take very long.

The only alternative i can see would be some sort of count function if there is one, in access u can count how many records have that ID... but thats really a query anyhow.

If you think about it you HAVE to query the database somehow to get that data..

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-09-2004 06:47

There are a couple of ways to do this and it is really code dependent.

The easiest is to make multiple calls to the DB. You will have the information, then make a call to check if there already is a parent, then if not make a seperate call to input the parent, else just place the child under the parent.

Or however you want to work it.

If you want some more help in the nitty gritty you will have to post the applicable code snippets, and DB design.

mobrul
Bipolar (III) Inmate

From:
Insane since: Aug 2000

posted posted 06-09-2004 14:50

You all are talking about the php doing the work...and that's probably how I'd do it.
BUT, I got to thinkin' "is there a different way?" and went looking through the mysql doc and found that clause ON DUPLICATE KEY UPDATE and the other clause IGNORE...and I've never used either before, but a brief reading tells me they might be a tool for this job. I think it would be dependant upon how you have your table set up.

I also may be way off course here. As I said, I've never actually used either, but it'll be something to experiment with in the near future.

kronk
Obsessive-Compulsive (I) Inmate

From:
Insane since: Jun 2004

posted posted 06-11-2004 20:27

thanks for the help everyone, I finally got it finished. What I did was inserted the child details then I queried the database and got a count(*) where parentid = the entered id number. then if the count was = 1, update the child table with the parent id number, if count = 0, add parent info then update child table. I learnt so much about mysql doing this project you guys wouldn't believe me.

Thanks once again for the advice.

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 06-12-2004 00:00

Seems a little akward to me.

It would make more sense to just query first, then add everything in one step based on the results, rather than adding, checking, adding, and updating again.

« BackwardsOnwards »

Show Forum Drop Down Menu