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: - randomly select a word from the database (I figured this out) - display the word (I figured this out) - allow the user to click the word - 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!
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.
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
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.
yup change echo '<a href="http://thewebsitelink.com">"$word"</a>'; to echo '<a href="http://thewebsitelink.com/page.php?word=' .$word . '">' . $word . '</a>';
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.
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.
<?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"
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="