Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

PHP MySql script

Codes here !

Moderators: macek, egami, gesf

PHP MySql script

Postby tk748 » Wed Apr 24, 2013 7:01 am

Hello Everyone,

I need to have a script coded to perform an action of my website. I am considering posting the project on the Freelancer website. I don't have much experience with writing this kind of script and I have no idea how much to pay for this work or if this is a difficult script to write. Can someone here advise me on this?

Here is what I am considering posting on Freelancer:

Store random numbers in a MySql table, then retrieve a number from that table and insert it into a target table each time a new record is created. To insure the uniqueness of the number, I want to delete the retrieved number from the source table as it is used (or another way of insuring uniqueness),

When users register on my Joomla website a new record is created in table _users. I have added a column in _users table named rand_num. I want a number from another table in the same database inserted into the rand_number column when a new record is created (i.e. when someone registers at my website)

Does this look like a difficult or time consuming scrip? Can you give me an idea of how much to pay for this work?

Thank you for any help you can give.

Regards,

Thomas
tk748
New php-forum User
New php-forum User
 
Posts: 1
Joined: Wed Apr 24, 2013 6:47 am

Re: PHP MySql script

Postby seandisanti » Thu Apr 25, 2013 8:08 am

Its a simple enough project that I'll just do it for you, and if you feel like making a donation based on the result, all the better. send a pm to discuss specifics
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: PHP MySql script

Postby seandisanti » Thu Apr 25, 2013 2:06 pm

Just in case it would help anyone else, I created 2 triggers for him, one before insert on his user table, and one for after. The trigger that fired before insert grabbed a random number from his number table like this:
Code: Select all
CREATE TRIGGER bi_users BEFORE INSERT ON users
FOR EACH ROW SET NEW.rand_num = (SELECT anumber FROM a_table ORDER BY RAND() LIMIT 1);

After the insert was completed the next trigger fired (so it would only execute on successful insert)
Code: Select all
CREATE TRIGGER ai_users AFTER INSERT on users
FOR EACH ROW DELETE FROM a_table WHERE anumber = NEW.rand_num;


There were a number of ways to accomplish this result but that one did it without having to add or modify any tables or php files.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.