zero-perfoliate
zero-perfoliate

Author Topic: problem with php code and refreshing  (Read 349 times)

Offline am529

  • New PHP Members
  • Posts: 1
  • Karma: +0/-0
problem with php code and refreshing
« on: January 28, 2009, 12:12:07 PM »
So I have this code on one of my pages

Code: [Select]
<?php  
$database
="blog_dat";
$languagetable $_POST['interests_en'];  
mysql_connect ("**********""********""****************");  
@
mysql_select_db($database) or die( "Unable to select database"); 
$result mysql_query"SELECT url FROM $languagetable ORDER BY RAND() LIMIT 1" )  
or die(
"SELECT Error: ".mysql_error());  
$num_rows mysql_num_rows($result);     
while (
$get_info mysql_fetch_row($result))
{  
foreach (
$get_info as $field);
}
?>
   
 
<iframe name="blog1" src=<?php print $field?> width="900" height="525"
frameborder="1" scrolling="yes"></iframe>

and it works using a variable posted from a form on the previous page.

What I'm trying to do is make the page refresh so that another random selection is pulled from the database table and displayed in the iframe, however I tried using javascript (and I tried the meta tag) to refresh the page every 10 seconds and when it does it comes up with an error saying:
Quote
"SELECT Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY RAND() LIMIT 1' at line 1"

I think this is because the variable "interests_en" is not being resent. Does anyone know a fix for this?

Offline PhPHelper

  • http://Digiscapers.com
  • Full Member
  • PHP Problem Solvers
  • ****
  • Posts: 179
  • Karma: +50/-0
    • Bad Apple Mail
Re: problem with php code and refreshing
« Reply #1 on: February 10, 2009, 05:39:16 PM »
for what your trying to do a better way would be using jquery to load data from the database and randomly change each time you can set the time for reload but the page would not reload it works like a slideshow.

create a new file call it load.php then put this code on it:

Code: [Select]
<?php
$prefixes 
= array('one','two','three','four','five','six','seven','eight','nine','ten');
// This selects a random element of each array on the fly
echo $prefixes[rand(0,count($prefixes)-1)];
?>


its an array of words this could be changed to be fed from a database instead.

Then in another file (the file you want to load into) put this in the header of the page:

Code: [Select]
<!-- load jquery file -->
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script>
//run when loaded
$(document).ready(function()
{

   var refreshId = setInterval(function()
   {
    $('#timeval h3').load('load.php?r='+ Math.random());//set div id and file to load
   }, 1000);//set timer count

   
});
</script>

the file loads in the jquery library file and then it creates a timer to load the php file ever 1000 miliseconds change it to suit then in the html put the in a div with an id of timer:

Code: [Select]
<div align="center" id="timeval"><h3></h3></div>
here's an example of a basic html file:

Code: [Select]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>your title</title>
<!-- load jquery file -->
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script>
//run when loaded
$(document).ready(function()
{

   var refreshId = setInterval(function()
   {
    $('#timeval h3').load('load.php?r='+ Math.random());//set div id and file to load
   }, 1000);//set timer count

   
});
</script>
</head>

<body>
<div align="center" id="timeval"><h3></h3></div>
</body>
</html>

that should sort it.

 

zero-perfoliate