Xtremer360 Posted February 25, 2011 Share Posted February 25, 2011 The purpose of this function is to go to the characters table and grab all of the characters that have a statusID of one however I want it to limit it to any ONE of those characters as this is a random image it's going to show and then I want it to have that charactes shortName and then use it to find their spotlight image from inside of the images/spotlight folder. All its showing right now in its spot is the the filename of the image when I call this function. function spotlight(){ $query = "SELECT * FROM characters WHERE characters.statusID = 1 LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $labels = array('shortName'); $img = array(); if($handle = opendir('images/spotlight/')) { $count = 0; while (false !== ($file = readdir($handle))) { if(strlen($file) > 2){ $img[$count] = $file; $count++; } } } echo $img[rand(0, (count($img)-1))]; } Quote Link to comment https://forums.phpfreaks.com/topic/228845-random-image/ Share on other sites More sharing options...
samshel Posted February 25, 2011 Share Posted February 25, 2011 SELECT * FROM characters WHERE characters.statusID = 1 ORDER BY RAND() LIMIT 1; Will give u 1 random record Quote Link to comment https://forums.phpfreaks.com/topic/228845-random-image/#findComment-1179754 Share on other sites More sharing options...
Xtremer360 Posted February 25, 2011 Author Share Posted February 25, 2011 Its still only echoing the name of the file and not the actual file. Quote Link to comment https://forums.phpfreaks.com/topic/228845-random-image/#findComment-1179757 Share on other sites More sharing options...
samshel Posted February 25, 2011 Share Posted February 25, 2011 try echo "<img src='".$img[rand(0, (count($img)-1))]."' >"; Quote Link to comment https://forums.phpfreaks.com/topic/228845-random-image/#findComment-1179773 Share on other sites More sharing options...
Xtremer360 Posted February 26, 2011 Author Share Posted February 26, 2011 Thank you that worked but I just wanted to point out I had to add images/spotlight into the image src attribute so that it'll be the right location of the proper file. Quote Link to comment https://forums.phpfreaks.com/topic/228845-random-image/#findComment-1179802 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.