
Originally Posted by
tgavin
You'd be better off creating a separate table for the hits and just inserting a new record every time somebody access the page

You criticize the overhead of an UPDATE, and then suggest burning away hard disk space by making a monstrous table of nothingness? Mein gott man... Maybe it's because I'm used to 100K page views a day, but that has to be the most absurd suggestion I've ever heard for tracking something as simple as hits. Don't even want to THINK about the seek time on that after a week. Hello IOWAIT.
I'd take "UPDATE likes WHERE id=? SET hits=hits+1" over what you just suggested ANY DAY on disk space alone... much less memory use when he tries to pull a total.
As to the OP's question, your logic looks ok, though I advise against using fetch_object as it's excess overhead for no good reason (row as an array is faster), and the double quotes make the code needlessly complex.
Code:
$results=$link->query('
SELECT * FROM likes
WHERE hits > 8
ORDER BY hits DESC
');
while ($data=$results->fetch_row()) {
echo '
<a href="like.php?like=',$data['id'],'">
',$data['content'],' | ',$data['hits'],'
</a><br />';
}
Though could you be more specific on what's going wrong? Is it outputting nothing? Is it displaying them out of order? Echo out msqli::error after the query, what's it saying?
Bookmarks