PHP - How To Get Most Viewed Topics
hi i am working on a project in which i have to retrieve the articles which are the most visited by the users. i have serched the internet but not find any useful code snippets. can any one guide me how to solve this problem.
Similar TutorialsSo, you know how on forums (including this one) the icon of a topic/forum will be greyed out if your account viewed that topic's latest post, regardless of which computer you viewed it on? How exactly does it store that? I know that logically it would store it on the Database, but I'm curious as to the actual implementation. It seems to me that storing every single topic you viewed it and when would take up huge numbers of rows, even for a small number of people, like say 100. If you have a forum with 1000's of people, each viewing even 3 topics a day, you're record numbers would be huge, slowing down the database. And calling your last viewed time for each and ever topic? Wouldn't that slow down the code excecution heaps? If you have any input, I'd love to hear it. It's a question I've been wrestling with in the back of my mind for a few years now ok, so here is the basic concept I want, but it is not working, everything is bold when the database is set to 1 for $read........could you take a look and help?: Code: [Select] <?php include 'config.php'; include 'opendb.php'; // if no id is specified, list the available articles if(!isset($_GET['id'])) { $query = "SELECT * FROM messages WHERE recipient ='$name' order by date desc"; $result = mysql_query($query) or die('Error : ' . mysql_error()); // create the article list while($row = mysql_fetch_array($result, MYSQL_NUM)) { list($from1, $recipient, $title1, $content, $id, $date, $read) = $row; if ($read == $userid){ $content1 .= "<br /><br /> $from1</p>\r\n"; $content2 .= "<br /><br /> <a href=\"/message.php?id=$id\">$title1</a>\r\n"; }else { $content1 .= "<br /><br /> <strong>$from1</strong></p>\r\n"; $content2 .= "<br /><br /> <a href=\"/message.php?id=$id\">$title1</a>\r\n"; } Hi there! I'm still getting use to using multiple rows when ordering in SQL, but I have a question. How can I display topics that are stickied first, then display all the threads below ordered by lastpost? I tried: //thread details $query = mysql_query("SELECT `date`,`lock`,`sticky`,`status`,`title`,`username`,`id`,`lastposter`,`lastpost` FROM threads WHERE parent = '{$_GET['forum']}' ORDER BY lastpost, sticky DESC LIMIT $start,$per_page") or die(mysql_error()); And the stickies do show up first, but all the regular threads aren't showing ordered by laspost DESC. Why is that? :/ Lastpost = datetime I am almost done with my website and I will use this thread to post small enhancements that would make my website better.........so #1, I have a code that will display news topics, how can I redo this code so that the topics are in reverse order and so that the title will be in bold lettering until it is read? Code: [Select] <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ www.flashbuilding.com -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['id'])) { echo 'Please <a href="login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Place Session variable 'id' into local variable $userid = $_SESSION['id']; // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM members WHERE userid='$userid' LIMIT 1"); while($row = mysql_fetch_array($sql)){ $name = $row["name"]; $phone = $row["phone"]; $username = $row["username"]; $address = $row["address"]; $city = $row["city"]; $state = $row["state"]; $zip = $row["zip"]; $cell = $row["cell"]; $email = $row["email"]; $accounttype = $row["accounttype"]; $rank = $row["rank"]; $badges = $row["badges"]; } ?> <?php include 'config1.php'; include 'opendb.php'; // if no id is specified, list the available articles if(!isset($_GET['id'])) { $self = $_SERVER['PHP_SELF']; $query = "SELECT id, title FROM news ORDER BY id"; $result = mysql_query($query) or die('Error : ' . mysql_error()); // create the article list $content = '<ol>'; while($row = mysql_fetch_array($result, MYSQL_NUM)) { list($id, $title) = $row; $content .= "<li><a href=\"$self?id=$id\">$title</a></li>\r\n"; } $content .= '</ol>'; $title = 'News'; } else { // get the article info from database $query = "SELECT title, content FROM news WHERE id=".$_GET['id']; $result = mysql_query($query) or die('Error : ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $title = $row['title']; $content = $row['content']; } include 'closedb.php'; ?> Code: [Select] <table width="600" border="0" align="center" cellpadding="10" cellspacing="1" bgcolor="#336699"> <tr> <td bgcolor="#FFFFFF"> <h1 align="center"><?php echo $title; ?></h1> <?php echo $content; // when displaying an article show a link // to see the article list if(isset($_GET['id'])) { ?> <p> </p> <p align="center"><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Back to News</a></p> <?php } ?> so once this topic is resolved.......I will probably post another small topic to look at. Hi Guys, I have a script that shows the user of my shop what they have looked at. I was wondering if someone can tell me how I can limit this so it only lists 10 and no more. Here is the code: Code: [Select] if(RECENTVIEWED ==1) { if(isset($_COOKIE['jimbeam'])){ $productUrl = SITE_URL."ecom/index.php?action=ecom.pdetails&mode="; $productUrl = $this->libFunc->m_safeUrl($productUrl); foreach ($_COOKIE['jimbeam'] as $name => $value) { $this->obDb->query="SELECT vTitle FROM ".PRODUCTS." WHERE vSeoTitle = '".$value."'"; $rsProd = $this->obDb->fetchQuery(); $this->obTpl->set_var("TPL_VAR_PRODUCTTITLE",stripslashes($rsProd[0]->vTitle)); $this->obTpl->set_var("TPL_VAR_PRODUCTURL",$productUrl.$value); $this->obTpl->parse("recent_blk","TPL_RECENT_BLK",true); } $this->obTpl->parse("mainrecent_blk","TPL_MAINRECENT_BLK"); } } Thanks, Jordan am currently building the cart system of a product, now there is this part wherein, the non-logged-in OR logged-in user should also be able to see the items that he/she viewed, how to do that?., am not asking for code snippets , just give me some ideas/hints/strategies/tips that may help me get the big picture on how to do this thing and proceed coding. Hello everyone I wonder if you could help me. I want to create a function called <?php function mythings($what) Which would allow me to pass an ID number to, such as <?php mythings(5419); What I want to do with that function is store the ID numbers of the past 6 items I have viewed, but I want to store each item as a SESSION once it has been passed. So essentially I would end up with the following 6 SESSIONS <?php $_SESSION['item1']; $_SESSION['item2']; $_SESSION['item3']; $_SESSION['item4']; $_SESSION['item5']; $_SESSION['item6']; So the "item1" SESSION would be the latest item ID passed through the function But then if I then passed a new ID through the function, that new ID passed would then become $_SESSION['item1']; and the current SESSION $_SESSION['item1']; would become $_SESSION['item2']; and $_SESSION['item2']; would become $_SESSION['item3']; and so on. This means I can do a list such as <?php print "Item 1".$_SESSION['item1']."<br>"; print "Item 2".$_SESSION['item2']."<br>"; print "Item 3".$_SESSION['item3']."<br>"; print "Item 4".$_SESSION['item4']."<br>"; print "Item 5".$_SESSION['item5']."<br>"; print "Item 6".$_SESSION['item6']."<br>"; ?> Does that make much sense? Can anyone help. Thanks very much all John Hello all, Wondering if you can help me, I am wondering if it is possible to get PHP to show the last websites you viewed, just giving the names of the websites in a list. If so? is there any pointers someone can give me as to how to learn to achieve something like this..I'd really appreciate the help! Hello people i have a system that takes people to generated pages from the database, the user has a field to input a video and others watching videos will get redirecting to tht video in time, what i want to know is how can i tell if a user viewed the page so to stop them getting redirected to it again by my random video query? The link always is video.php?id=blabla the id changes every refresh, so i can call that id to check if there on the page but how can i tell if they have been on it before. This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=327636.0 This script ...
<?php echo "Your IP Address: <br/>"; print_r($_SERVER['REMOTE_ADDR']); ?>... prints: ::1I am looking to have the IP address from which the site is viewed printed on screen. What is the issue, here, with the script I have? I have been trying this on localhost and I am using XAMPP. hey all, i have an issue, i have a directory site called hackingtoolz.tk and if you go to it, you will see a list of folders as it is just a directory the problem is how to i stop the banner from apearing in the directory. i have tried changing the chmod to 4000 and that just made the jpeg stay their and the banner screw up if you go to the site you will understand what i mean better hope you can help cheers nick <?php query_posts('meta_key=post_views_count&posts_per_page=3&orderby=meta_value_num& order=DESC'); if (have_posts()) : while (have_posts()) : the_post(); ?> <ul class="rpul"> <li> <div class="class="post-thumb wp-post-image" style=' '> <?php if ( has_post_thumbnail() ) : ?> <?php the_post_thumbnail('thumbnail') ?> <?php endif ?> </div><div class='cat-post-text'> <h1> <a href="<?php the_permalink(); ?>"><?php the_title(); ?>
so the user is reading a story, to finish reading he has to click a link that redirects them to the signup page. Code: [Select] <?php session_start(); $beginurl = $_SERVER['HTTP_REFERER']; $_SESSION['beginurl'] = $beginurl; echo $_SESSION['beginurl']; ?> <html> <head> </head> <body> <script type="text/javascript"><!-- location.replace("http://www.mysite.com/members/"); //--></script> </body> </html> When they get to the second page, they have to click a link that opens up a modal. this is the code that runs when they hit the register button Code: [Select] session_start(); $beginurl = $_SESSION['beginurl']; $beginurl= (isset($_SESSION['beginurl'])) ? $_SESSION['beginurl'] : 'Error'; if( $_SESSION['status'] ='authorized') $_SESSION['$makemodal'] = 0; //sends the user to the page upon successful password credential if(!isset($_SESSION['SESS_USERID'])||(trim($_SESSION['SESS_USERID']=='admin'))) { echo '<script language="javascript">'; echo "top.location.href = $beginurl"; echo '</script>'; exit(); } Am I passing this variable correctly? and I'm not sure if the top.location.href towards the bottom is correct either, right now after I hit the register button I'm redirected to a blank page where the url is, "http://www.mysite.com/function Error() { [native code]}" Hello, I was wondering how to create the 'This post is being viewed by user1, user2, user3 and ... guests' on a certain location of the forum/website. I was thinking about having all these usernames / guests stored in the mysql database, however this caused an issue for me, since I got no idea if you can/are allowed to place an array in a table. I am hoping someone out here knows what is the easiest/most efficient way of doing this. Thanks in advance. |