Word of the day -- Need help!

Discussion in 'Programming' started by MCJim, Apr 26, 2008.

  1. #1
    I created a database of words using MySQL and I need a bit of help making a 'word of the day' feature.

    I would like to:
    1. - randomly select a word from the database (I figured this out)
    2. - display the word (I figured this out)
    3. - allow the user to click the word
    4. - if the user clicks the word, it refreshes the page (not a subdirectory; its not a link) and shows the definition. The definition is also taken from the same database as the word.
    If anyone can help or at least point me in the right direction I will be very thankful. I'm working on it, but this can save me a lot of time. Thanks!
     
    MCJim, Apr 26, 2008 IP
  2. ASPMachine

    ASPMachine Peon

    Messages:
    723
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Are you wanna say like this page "http://borolook.com/Free_Directory_Submission_to_10000.asp"? Here the urls are hidden and when you click at any link, the action is on the same page "Free_Directory_Submission_to_10000.asp". But in every click on the different titles, you'll get different directories site.

    At first I thought to display the entire directories list together, but for some reasons, I added the entire list on database.
     
    ASPMachine, Apr 26, 2008 IP
  3. helpplease

    helpplease Banned

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    1 minute:
    basic flow of page

    <?php
    if(isset($_GET['word_id'])) {
    mysql_query("SELECT * FROM table WHERE word_id='. $_GET['word_id'] .' LIMIT 1");
    echo "result with word description from query";
    } else {
    // echo a random word
    mysql_query('SELECT word FROM table ORDER BY RAND() LIMIT 1');
    echo '<a href="?word_id='.$query_result['word_id'].">'.$query_result['word_id'].'</a>';
    }

    a bit of code missing from that, but thats the flow of the app
     
    helpplease, Apr 26, 2008 IP
  4. MCJim

    MCJim Peon

    Messages:
    163
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for your help!

    Another question, is it possible to have a PHP variable in an html link? For example: echo '<a href="http://thewebsitelink.com">"$word"</a>'; ? I know that code doesn't work but is there anyway to do that? What I'm basically trying to do now is to pass the clicked word as a variable.
     
    MCJim, Apr 26, 2008 IP
  5. helpplease

    helpplease Banned

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yup

    change
    echo '<a href="http://thewebsitelink.com">"$word"</a>';

    to
    echo '<a href="http://thewebsitelink.com/page.php?word=' .$word . '">' . $word . '</a>';
     
    helpplease, Apr 26, 2008 IP
  6. MCJim

    MCJim Peon

    Messages:
    163
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks again :)

    Yet another question though, how can I make an if statement so that if a word is clicked it is compared to another variable? I would like the click word to be compared to another variable and to have the page echo out if the clicked word equaled the variable.
     
    MCJim, Apr 26, 2008 IP
  7. helpplease

    helpplease Banned

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    if($_GET['word'] == $variable) {
    echo "out";
    }

    :)
     
    helpplease, Apr 26, 2008 IP
    MCJim likes this.
  8. MCJim

    MCJim Peon

    Messages:
    163
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    OK, that works, but how about for this?

    <?php
    echo '<a href="http://website.php?word=' .$one . '">' . $one . '</a><br>';
    echo '<a href="http://website.php?word=' .$two . '">' . $two . '</a><br>';
    if($_GET['SELECTED VARIABLE, im not sure what goes here'] == $answer) {
    echo "match";
    }
    ?>
    PHP:
    In this example, there are multiple variables. How do you tell which one the user clicks and compare it to the answer variable?

    Again, thank you very much for all your help. I gave you +rep. As you can see, I'm new to all of this and I'm trying understand how stuff works.
     
    MCJim, Apr 26, 2008 IP
  9. helpplease

    helpplease Banned

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    <?php
    echo '<a href="http://website.php?word=' .$one . '">' . $one . '</a><br>';
    echo '<a href="http://website.php?word=' .$two . '">' . $two . '</a><br>';
    if($_GET['word'] == $answer) {
    echo "match";
    }
    ?>
    PHP:
    $_GET holds all values passed in the url so for an url

    http://domain.com/page.php?value1=egg&value2=shell

    then
    $_GET['value1'] = "egg"
    $_GET['value2'] = "shell"

    :)
     
    helpplease, Apr 27, 2008 IP
  10. MCJim

    MCJim Peon

    Messages:
    163
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I'm still having some problems though. If I use that code, when I click a link it doesn't process the if-statement correctly and match never appears.

    Maybe the linking is wrong? It displays as "http://website.php?word="
     
    MCJim, Apr 27, 2008 IP
  11. MCJim

    MCJim Peon

    Messages:
    163
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Never mind, I solved out the issue. My database was improperly formatted!
     
    MCJim, Apr 27, 2008 IP