-
PHP reload random record.
Not sure if this should go in javascript or PHP forum. I have a PHP script that pulls 1 random record from MYSQL database on my website. What I would like for it to do is every 10 seconds pull another random record. I can't do it with PHP alone, and I was told I could use javascript to effectively reload the PHP script every 10 seconds, causing the random record it is pulling to change. Any ideas on how to write this code? Here is my PHP code:
<?php require_once('../Connections/john.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_john, $john);
$query_listing = "SELECT * FROM testimonials_display ORDER BY RAND() LIMIT 1
";
$listing = mysql_query($query_listing, $john) or die(mysql_error());
$row_listing = mysql_fetch_assoc($listing);
$totalRows_listing = mysql_num_rows($listing);
And this is the code in the body of the document:
<?php do { ?>
<p> <?php echo $row_listing['comment']; ?></p>
<hr>
<?php } while ($row_listing = mysql_fetch_assoc($listing)); ?>
-
-
Javascript. More specifically AJAX. Post this in the javascript forum. I don't know how or I'd tell you.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks