| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Senior Member ![]() | MYsql I want to make it so people can enter their email into a table and later an email can be randomly picked from the table as a winner for a free domain name. Is there a way to display the current amount of emails in the table. Check the table to be sure that the email isnt already present. And pick a name at random? |
| |
| | #3 (permalink) |
| NamePros Member | such a commercial world we living in :-) PMs sent, how it helped, I am going off!
__________________ FOR SALE: infochecker.com/net | tophosting.us | flyeasier.com | gofornews.com |wantedprice.com | talkspeed.com | organiclcd.com | trade-on-line.com | nexane.com getprivate.info | getfresh.info | unsaved.info |
| |
| | #6 (permalink) |
| Senior Member | Or: let's say you setup the form <input type="text" size="25" name="email_addr"> when the page is submitted, you can check that email doesn't exist: <? $email_addr = $_POST['email_addr']; $sql_emailchk = mysql_query("SELECT * FROM emails WHERE email_addr='$email_addr'"); $sql_result = mysql_num_rows($sql_emailchk); if ($sql_result > 0) { // this means that email already exists // show error or some page with error... } else { $sql_insert_email = mysql_query("INSERT INTO emails VALUES('', '$email_addr')"); } ?> That was a basic function, now you make sure that email isn't duplicate of another. To show total emails in your database, you can use count..and you can use <? $sql_getnum = mysql_query("SELECT * FROM emails"); $sql_num = mysql_num_rows($sql_getnum); // this will return number of rows echo $sql_num; // should be some number... ?> Well, basically, if you want to get one random result from your database/table, you could use something like RAND(); to randomize a result.. heres a tip: Just call this function: function GetRandomWinner() { $sql_getrandom = mysql_query("SELECT * FROM emails ORDER BY RAND() LIMIT 0, 1"); $row = mysql_fetch_array($sql_getrandom); extract($row); echo 'Winning email: '; echo $email_addr; } To call this function inside php, just use <? GetRandomWinner(); ?> To get more than one winner randomly, increase the LIMIT 0, <b>1</b> Not a complete code, but I hope it is helpful. |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| HOWTO: Install the Apache Web Server, Perl, PHP, and MySQL on Windows | deadserious | Webmaster Tutorials | 96 | 05-27-2007 01:24 PM |
| Tutorial: How to Install Apache2 MySQL and PHP on Windows | deadserious | Webmaster Tutorials | 35 | 09-21-2005 09:46 PM |
| mysql problem | Shof515 | Programming | 3 | 12-14-2004 09:20 PM |
| Tutorial: Getting Started With MySQL (The Basics) | deadserious | Webmaster Tutorials | 3 | 04-18-2004 01:17 PM |