Mind blowing SEO improving and Google rank increasing Signature Rotator SEO Tool.

Thread: 

is there any way to reload automatically ?

Ads
banner
banner
banner
lion Offline referral

Posts: 122
Joined: May 2014
Reputation: 0

#1
Member
Hello
I used this code to show my last forum's post :
Code:
<?php
define("IN_MYBB", 1);
require_once("./global.php"); // Change this if needed
$tlimit = 5; // How many titles you want

$query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY `tid` DESC LIMIT $tlimit");
while($fetch = $db->fetch_array($query)){
echo '<a href="./showthread.php?tid='.$fetch['tid'].'">'.$fetch['subject'].'</a><br />' . "\n";
}
?>

I want to know that is there any way to reload last post automatically with AJAX in this code ?
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#2
Support Team
Hi you can try this jQuery auto refresh div code?
PHP Code:
<?php
define
("IN_MYBB"1);
require_once(
"global.php"); // Change this if needed
$tlimit 5// How many titles you want

$query $db->query("SELECT t.*, u.username
        FROM "
.TABLE_PREFIX."threads t
        LEFT JOIN "
.TABLE_PREFIX."users u ON (u.uid=t.uid)
        WHERE 1=1 
$unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
        ORDER BY t.lastpost DESC 
        LIMIT 
$tlimit");
        
while(
$thread $db->fetch_array($query))
    {
        
        
$test .= '<a href="./showthread.php?tid='.$thread['tid'].'">'.$thread['subject'].'</a><br />' "&#092;n";

    }
    
?>

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    setInterval(function() {
        $('#latest_threads').load('test.php').fadeIn("slow");
    }, 5000)
});
</script>
</head>
<body>
<div id="latest_threads">
<?php
echo $test;
?>
</div>
</body>
</html> 
lion Offline referral

Posts: 122
Joined: May 2014
Reputation: 0

#3
Member
Thanks
but it shows this error when reload :
'; var_dump($mybb); var_dump($lang); echo ''; ?>

and another question , is there any way to show prefix in this code ?
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#4
Support Team
Make sure the path to globa.php is correct.

In here
Code:
$('#latest_threads').load('test.php').fadeIn("slow");
replace test.php with the name of your page.

For thread prefix try:
PHP Code:
$thread['prefix'

PHP Code:
$test .= '<a href="./showthread.php?tid={$thread['tid']}">{$thread['prefix']} {$thread['subject']}</a><br />' "&#092;n"
lion Offline referral

Posts: 122
Joined: May 2014
Reputation: 0

#5
Member
I'm using this code in Header Template in my forum

I have developed this code and I have a problem to match it to reload it with AJAX
may i p.m it to you to check it ?
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#6
Support Team
OK I will wait for you PM.





User(s) browsing this thread: 1 Guest(s)