Jump to content

Creating a site with, words that display in ranked order; on each load.


Recommended Posts

I came up with an idea that i will not specificily describe, that involves having a page that displays a series of words in a paragraph format by this i mean something along the lines of:

 

Word Word Word Word Word Word Word Word

Word Word Word Word Word Word Word Word

Word Word Word Word Drow Word Word Word

Word Word Word Word Word Word Word Word

Word Word Word Word Word Word Word Word

 

For now that is all i plan on working on and filling up these words and expanding the size of the database of words.

But there is a major part to it that i do not know how to do.

 

I would like, every single word to be a link / action. When someone clicks on a word - the word is given a vote. This vote will move this word up according. By this i mean.

When the page is loaded for the first time. It will be shown as above. each word will have a score of: 1 When the first user clicks on the word: Drow, it will be given a score of: 2. Meaning that this will move to being the first word in the list. Like:

 

Drow Word Word Word Word Word Word Word

Word Word Word Word Word Word Word Word

Word Word Word Word Word Word Word Word

Word Word Word Word Word Word Word Word

Word Word Word Word Word Word Word Word

 

This means that the second person that views the website will see it in this order. And so on, meaning the more people that vote. The higher up certain words will get. until all the words are in an order of most voted for and most popular.

 

I have enough knowledge of coding to maintain such a website, and create other basic sites. But scripting these actions was beyond me. and was wondering, is it possible.

And wether anyone could help me at all?

If you need me to be more specific, let me know.

 

My host supports Php, so have chosen to go down this route; but to be completely honest. I've gotten myself totally confused, and I'm not really sure how to even start this.

Help please. :(

 

Luke.

Well, to start off you want to create a table, with a column for the primary key, the word itself, its rank, number of clicks, and any other information you want.

 

You should go through the database, and all the words in the table, ordered by votes, and output them, perhaps in an HTML table to make them look nice. You will want to make the each word a link, with a get variable that is specific to its primary key. You want that link to go to a different php page, that will update the count of votes on a specific entry based on the get variables ID.

 

thats how I would do it anyways. Hope that helps!

Thanks for the help - it's definetly cleared up alot of the method, but i'm fairly new to php, i mean; I know how to make websites, using basic coding and how to maintain one using HTML, XHTMl, CSS. But i've rarely used Php. and was wondering, could you perhaps give me a rough idea of the coding i would use; or any guides specific to the steps i would take?

Sure! I'll assume you know how to create a database table, and how to set up the rows and columns (if not, there are many very good tutorials out there for it. just google php and mysql table), and I will also assume you know basic mysql functions like mysql_query, fetch array, etc. etc

 

so here is how I would get the list of words (assuming that your table is composed of only the words you want to output

 

sql = "SELECT * FROM myWords ORDER BY votes";
$query = mysql_query($sql);

echo "<table>";//gonna put stuff in table for formatting
$i = 1;
echo "<tr>";
while($row = mysql_fetch_assoc($query)){
echo "<td>" . $row['word'] . "</td>";//assuming the word column is called 'word'
if ($i % 5 == 0){
//% = modulus. Its to basically to see if this is the fifth row in the column. do a google search for 
//modulus to find out more info on it
//I want to make each row 5 columns long, so every 5th word I end the
//current row and start a new one
echo "</tr><tr>";
}
$i++;
}//end while

echo "</tr></table>"

 

Now to make each word votable, instead of just echoing the word, I would make the word a link. Lets assume the primary key is the column 'id'. well I would change the inside of my loop to the following

 

while($row = mysql_fetch_assoc($query)){
echo "<td><a href='vote.php?id=".$row['id'].">" . $row['word'] . "</a></td>";//assuming the word column is called 'word'
if ($i % 5 == 0){
echo "</tr><tr>";
}
$i++;
}//end while

 

Now, on the vote.php page, which will do the updating, I would have something like

 

$id = $_GET['id'];//this is from the vote.php?id= part of the link. id is the get variable, and $row['id'] is the value

$insert = "UPDATE myWords set votes = votes + 1 WHERE id='$id'"
$query = mysql_query($insert);
echo "Word updated!";

 

this is very basic, but includes the basic logic required. Hope that helps!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.