mysql help
#1

Im no expert in mysql, so ill ask here and maybe some of you guys know what to do
I have code in OnGameModeInit to create tables in the database if they dont exist.

pawn Код:
CREATE TABLE IF NOT EXISTS ....
I also want to insert 10 rows of information to, its actually just 1 field of information that is important to be created, the ID field.

I tried a x10 loop with:
pawn Код:
INSERT INTO .....
What i didnt think about is that it will create 10 new rows every time OnGameModeInit is called.

So the question is, how do i make it detect if the 10 rows are already in the DB?
Reply
#2

Erm.. why not just delete the code ? Or store it somewhere and when you need to insert it in DB just paste it in phpmyadmin or whatever you have.. ?O.o
Reply
#3

It depends on what sort of information you're storing in your table, I guess, but the only way to approach this issue of yours is using a SELECT query.

You can, for instance, select the number of rows in the table.
SELECT COUNT(*) FROM table
Then the first and only value returned by the query is the amount of rows. Retrieve this (either using the regular mysql_* functions or maybe the cache feature, check my signature for that) value and see if it is 10. If no, insert the rows.
Reply
#4

AndreT, you are awesome! Thank you so much!

Edit: You must spread some Reputation around before giving it to AndreT again.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)