Jump to content

php/mysql question


Dville

Recommended Posts

So i'm making a clone of digg.com.

This can be located at [a href=\"http://tekkenfan.sytes.net/digg\" target=\"_blank\"]http://tekkenfan.sytes.net/digg[/a]
I am using this while loop to pull all data from the database

[code]while($row = mysql_fetch_array( $result )) {[/code]

and then this, to ouptput the data
[code]echo "<table class='sample' valign='top' border='1' cellpadding='5'> <tr> <th width='49' rowspan='2'>";
echo $row['hits'];
echo "<br>";
echo "<u><font size='2'>Hit This!</u></font>";
echo "</th>";

echo "<td width='575'>";
echo "<b>";
?>
<a href="<?php echo $url; ?>"><?php echo $row['title'];?></a>
<?php
echo "</b>";
echo "<br><font size='2'>Article posted on:";
echo $row['date'];
echo "</td> </tr> <tr> <td width='575'>";
echo $row['body'];
echo "</td> </tr> </table>";
echo "<br>";

}[/code]


As you can tell, i'm giving a spot for a 'digg this/hit this' link. . .This is of course linked to a db field called 'hits' that i want to use as a 'total' hits that particular story has gotten. And with each click. . .it will add 1 to that certain story's db field.

I assume the way to initiate this process is to make each 'hit this' line, in the table, link to a blah.php page. Having this page do the mysql changes, then maybe give a 'thank you' message, pausing, then doing a header to redirect back to the index.

The issue I come across is how to tell the difference between the stories. How will I go about something like this?

Thanks in advanced for anyone that takes the time to reply.
Link to comment
Share on other sites

Each story when entered into the database should have an ID number, use that number to ID each story and also become the ID php uses to update the hit number.

If I am way off base please explain your situation a little better and I'll redo my reply
Link to comment
Share on other sites

I am such a noob at everything php and mysql related. What's in my code so far, was learned right when I needed to do that specific task.

Is the above code the blah.php?

if so, how do i pass it along via _session?

Here is my tables code, cause I really dont know what exactly is needed to customize.

[code]// Create a MySQL table in the selected database
mysql_query("CREATE TABLE articles(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
title VARCHAR(255), link VARCHAR(255), category VARCHAR(30), hits INT, date VARCHAR(50), body VARCHAR(5000))");

echo "Table Created!";

?>[/code]

As much explaination of code is greatly appreciated
Link to comment
Share on other sites

Ok I'll try this again, even I was confused by my last post...LOL

Ok on your main page as linked in your first post you need to query the database and assign the id with the hit this link.

[code]

$linklist=mysql_query(
        "SELECT id, title, link, category, body FROM articles");

while ($all = mysql_fetch_array($linklist)) {
  $id=$all['id'];
  $title=$all['title'];
  $link=$all['link'];
  $category=$all['category'];
  $body = $all['body'];
  
//then your layout but the hit this link needs to be as follows

echo "<a href='hit_this_link.php?appid=$id'>[HIT THIS]</a>

// that will attach your id for the GET statment on the processing page
[/code]

Next you need to create a php page to process the hit this
call it hit_this_link.php

[code]
$aprid = $_GET['appid'];

UPDATE articles SET hits = hits + 1 WHERE id='$aprid'");

include_once "the_name of your main page.php";
[/code]

The rest you'll have to figure out on your own :-)
Link to comment
Share on other sites

I use the following to query my database

[code]$result = mysql_query("SELECT * FROM articles ORDER BY id DESC LIMIT ".$start.", ".$limit);[/code]


Can I keep it like that. . .instead of how you put it as

[code]$linklist=mysql_query(
        "SELECT id, title, link, category, body FROM articles");[/code]

since * pulls everything. . .that would be the same, correct?

i think so. . .but yea. . .it's coming together in my head now. i'll post updates in an hour or so
Link to comment
Share on other sites

dood you freaking rock!!!!!

I'm so new, when i first saw the code it was foreign. . .but now that I looked at it for 10 minutes and got back into it. . . .it works!!!!!!!

man I've been putting this off for 5-6 days, being so lost on how I would go about doing this.

if you or anyone could give a detailed explaination, or a link to an article that explains what i just did. . .i would be very greatful. I'd rather learn this than just cut and paste code.

Thanks again!!!!!


EDIT - due to duplicate updates being made, i needed to do a header, insead of include.
but yea, this works fantasticly
Link to comment
Share on other sites

The quick explination... You are simply applying the ID number to the exact article when you create the link, that means anything you do with that link will carry the ID number so it applies changes only to that exact article. If you look over it a few times it will begin to become really clear... Glad it worked well for you.

BTW I just checked the page... It all looks really great :-)
Link to comment
Share on other sites

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.