The Little Guy Posted October 23, 2007 Share Posted October 23, 2007 I have a database with url's in it, and I want to load one at random into a frame, when a link is clicked I want to load a new random url into the frame I can do everything except load the new url into the frame, how would I do that? Link to comment https://forums.phpfreaks.com/topic/74503-solved-load-url-into-a-frame/ Share on other sites More sharing options...
marcus Posted October 23, 2007 Share Posted October 23, 2007 $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"; Link to comment https://forums.phpfreaks.com/topic/74503-solved-load-url-into-a-frame/#findComment-376519 Share on other sites More sharing options...
manixrock Posted October 23, 2007 Share Posted October 23, 2007 <?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'); ?> Link to comment https://forums.phpfreaks.com/topic/74503-solved-load-url-into-a-frame/#findComment-376522 Share on other sites More sharing options...
The Little Guy Posted October 23, 2007 Author Share Posted October 23, 2007 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" />' ?> Link to comment https://forums.phpfreaks.com/topic/74503-solved-load-url-into-a-frame/#findComment-376523 Share on other sites More sharing options...
marcus Posted October 23, 2007 Share Posted October 23, 2007 And your problem? Link to comment https://forums.phpfreaks.com/topic/74503-solved-load-url-into-a-frame/#findComment-376529 Share on other sites More sharing options...
The Little Guy Posted October 23, 2007 Author Share Posted October 23, 2007 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. Link to comment https://forums.phpfreaks.com/topic/74503-solved-load-url-into-a-frame/#findComment-376530 Share on other sites More sharing options...
marcus Posted October 23, 2007 Share Posted October 23, 2007 The frame URL is: http://ff.phpsnips.com/incl/loadNewURL.php Link to comment https://forums.phpfreaks.com/topic/74503-solved-load-url-into-a-frame/#findComment-376535 Share on other sites More sharing options...
The Little Guy Posted October 23, 2007 Author Share Posted October 23, 2007 I know Link to comment https://forums.phpfreaks.com/topic/74503-solved-load-url-into-a-frame/#findComment-376538 Share on other sites More sharing options...
The Little Guy Posted October 23, 2007 Author Share Posted October 23, 2007 [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] Link to comment https://forums.phpfreaks.com/topic/74503-solved-load-url-into-a-frame/#findComment-376564 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.