Vivid Lust Posted December 23, 2007 Share Posted December 23, 2007 Why doesnt this work? :s <?php //Connect and slecets database $query = mysql_query( "SELECT MAX(id) FROM banner" ) or die(mysql_error()); $rand=rand(1,.$query.); header('Location:http://imgsurf.wsnw.net/banner.php?id='.$rand.); exit (); ?> Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/82926-rand-help/ Share on other sites More sharing options...
PHP_PhREEEk Posted December 23, 2007 Share Posted December 23, 2007 Remove the dots... <?php $rand=rand(1,$query); Err, wait, that's only a Resource ID there.. you'll need to fetch the row first before you can use it in rand() PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/82926-rand-help/#findComment-421734 Share on other sites More sharing options...
papaface Posted December 23, 2007 Share Posted December 23, 2007 For a start $rand=rand(1,.$query.); should be $rand=rand(1,$query); But the actual way you're doing it wont work. Remove the exit; And look into how you get values from mysql. Quote Link to comment https://forums.phpfreaks.com/topic/82926-rand-help/#findComment-421735 Share on other sites More sharing options...
asmith Posted December 23, 2007 Share Posted December 23, 2007 as all other said . $result = mysql_fetch_array($query); $rand=rand(1,$result[0]); note that $result is an array. Quote Link to comment https://forums.phpfreaks.com/topic/82926-rand-help/#findComment-421739 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.