开发者

How can I show a quote from database in a cycle order?

I want to show only one quote from my da开发者_开发问答tabase table by cyclic order when the page refresh or reload. I don't want to do it randomly. cycle like: 1,2,3....10 then back to 1. I need to do that using php or jquery. Please help


store this views number in session like so:

<?php
session_start(); 
$_SESSION['views'] = 1; // store session data
echo "Pageviews = ". $_SESSION['views']; //retrieve data
?>

from http://www.tizag.com/phpT/phpsessions.php


You can set a cookie with the current index, and every visit just increment it by one.


session_start();

if (empty($_SESSION['quote_num']) || !is_numeric($_SESSION['quote_num']) || $_SESSION['quote_num'] >= 10) {
   $_SESSION['quote_num'] = 1;
} else {
   $_SESSION['quote_num'] += 1;
}


// Now execute your query. Make sure to do proper escaping of your query.
// SELECT .... WHERE quote_num = $_SESSION['quote_num']


session_start();
if (!$_SESSION['c'])
{
    $_SESSION['c'] = 0;
}

if ($_SESSION['c'] == 10)
{
     $_SESSION['c'] = 0;
}

$_SESSION['c']++;
$result = mysql_query("SELECT * FROM cycle WHERE id = ".$_SESSION['c']);
$row = mysql_fetch_assoc($result);
echo $row['id'];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜