Jump to content

Recommended Posts

$sql = "SELECT * FROM `urls` ORDER BY RAND()";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
echo "<frame src=\"{$row['url']}\" frameborder=\"0\" width=\"500\" height=\"auto\" scrolling=\"yes\">your browser does not support frames</frame>\n";

<?php
$r = mysql_query('SELECT * FROM mytable ORDER BY RAND() LIMIT 1');
?>

 

but if you have a lot of links this is a bit slow since it has to randomly order the list. Instead you should do 2 mysql queries:

 

<?php
$res = mysql_query('SELECT COUNT(*) AS count FROM mytable');
$row = mysql_fetch_assoc($res);
$rows_count = $row['count']; // to get the count of rows in your table, then:
$r = mysql_query('SELECT * FROM mytable LIMIT '.mt_rand(1, $rows_count).', 1');
?>

I have that

 

main page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Search Results</title>
</head>
<frameset border="0" frameborder="0" framespacing="0" rows="104px,*">
<frame src="incl/topFrame.php" />
<?php include 'incl/loadNewURL.php'; ?>
</frameset>
</html>

 

topFrame.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>FrameTop</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="headContainer">	
	<div class="logo_right"><a target="bottomFrame" href="/incl/loadNewURL.php"><img src="/images/faf_logo_right.gif" /></a></div>
	<?php include 'btns.php'; ?>
</div>
<div class="otherNav">
	<a href="/join.php" target="_parent" style="font-weight:bold;color:#000000;text-decoration:none;">Join us today, and start adding websites now!</a>
</div>
</body>
</html>

 

loadNewURL.php:

<?php
@include 'db.php';
@include '../db.php';
$sql = mysql_query("SELECT url FROM sites ORDER BY RAND() LIMIT 1");
$row = mysql_fetch_array($sql);
echo '<frame src="http://'.$row['url'].'" name="bottomFrame" />'
?>

Go here: http://ff.phpsnips.com

 

click on the large image

 

the image moves to the upper right of the page and a website from the database is placed on the bottom, click it again

 

nothing displays in the bottom frame. that is the problem.

[code]I GOT IT!

all you need to do is do a header redirect

<?php

@include 'db.php';

@include '../db.php';

$sql = mysql_query("SELECT url FROM sites ORDER BY RAND() LIMIT 1");

$row = mysql_fetch_array($sql);

$url = 'http://'.$row['url'];

header("Location: $url");

exit;

?>[/code]

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.