Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2011
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Generating Words PHP

    Hi im looking to make some kind of match thing were 2 people recieve similar emails. In the email they will both be given a random word. By random I mean 'Banana' or 'Turqoise' etc

    How do I do this?
    My initial guess is to create a random number and pick the word out of a list at this corresponding number. How would I compile the list and what platform would i make it on? I am new to all this stuff :s

    Thanks guys

  • #2
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    This project could be done a number of ways.

    You could use a database (MySql being a very popular choice) to store your desired words. Then, yes, you would pluck them from the database by a randomly selected key or by using something like SELECT * FROM `table` ORDER BY RAND() LIMIT 0,1; (if your database isn't enormous).

    Otherwise, you could skip the database and just use a PHP array variable to store your words and select a random entry from that array.

    As for compiling the list in the first place... well that's up to you.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • Users who have thanked Rowsdower! for this post:

    crazyracky (05-24-2011)

  • #3
    New Coder
    Join Date
    Mar 2011
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks for that! On the MySQL point I was wondering if there was something else you may be able to give me a quick view on...

    I wanted to match names in a table. Thing is users input different names. I understand I can use % to match Jo% with Jo, Joe and Joseph, but is there any other ways to match words that may not be exact but very similar?

    So far I have only got words down to lowercase to get better matching, but I wanted to match say "Rick Smith" to "Rich Smith", the jist been names maybe slightly different but out of say 5,000 people chances are the match is correct, as the users may have entered a name slightly differently.

    Thanks

  • #4
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Hmm. Well if you're storing the first and last names in different columns of the table then you would just do a wildcard on each one (or on one but not the other, or whatever you want to do).

    Something like:
    Code:
    SELECT * FROM `table` WHERE first_name LIKE 'Ri%' AND last_name LIKE 'Smi%';
    Or:
    Code:
    SELECT * FROM `table` WHERE first_name LIKE 'Ri%' AND last_name = 'Smith';
    Otherwise you're looking at using "regular expressions" (check google if you're not familiar with these) to get the job done. Those can be pretty sophisticated but also pretty difficult to create. There is MySql syntax for this:

    http://dev.mysql.com/doc/refman/5.1/en/regexp.html

    Regular expressions are pretty neat though.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •