phpretard Posted August 17, 2008 Share Posted August 17, 2008 I only want to display only one disint image on a page at s time this... if you refresh sometimes shows 2 $result = mysql_query("SELECT DISTINCT image FROM ads ORDER by Rand() LIMIT 1"); while($row = mysql_fetch_array($result)) { $ADimage=$row['image']; $echo= "<div align='center'><img src='ads/$ADimage'></div>"; } Any help tonight? Link to comment https://forums.phpfreaks.com/topic/120047-random-distinct/ Share on other sites More sharing options...
marcus Posted August 17, 2008 Share Posted August 17, 2008 Why not just $sql = "SELECT image FROM `ads` ORDER BY RAND() GROUP BY image LIMIT 1"; or even drop the group by. Link to comment https://forums.phpfreaks.com/topic/120047-random-distinct/#findComment-618395 Share on other sites More sharing options...
phpretard Posted August 17, 2008 Author Share Posted August 17, 2008 I think I screwed up my question. I need 5 images to show up from the DB. If the same image is going to be displayed more than once (one the same page) than I would like to have a default image its place. Do you know what this means? Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /backup/hsphere/local/home/mercodesigns/mercodesigns.com/classifieds/pages/ads.php on line 6 Link to comment https://forums.phpfreaks.com/topic/120047-random-distinct/#findComment-618401 Share on other sites More sharing options...
marcus Posted August 17, 2008 Share Posted August 17, 2008 Ok, this means you have a mysql error. mysql_query(QUERY) or die(mysql_error()); just try this $sql = "SELECT image FROM `ads` ORDER BY RAND() LIMIT 1"; Link to comment https://forums.phpfreaks.com/topic/120047-random-distinct/#findComment-618403 Share on other sites More sharing options...
phpretard Posted August 17, 2008 Author Share Posted August 17, 2008 Sorry about the confusion. Link to comment https://forums.phpfreaks.com/topic/120047-random-distinct/#findComment-618407 Share on other sites More sharing options...
phpretard Posted August 17, 2008 Author Share Posted August 17, 2008 I have searched and searched and found some thing about cookies and sessions and now my brain hurts. Anymore thoughts here? Link to comment https://forums.phpfreaks.com/topic/120047-random-distinct/#findComment-618455 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.