Jump to content

[SOLVED] load url into a frame


The Little Guy

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" />'
?>

[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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.