pixeltrace Posted May 5, 2008 Share Posted May 5, 2008 hi, i need help, i need to display images limit to 1 only at random select. this is the code that i used <? function show_latest_banner() { global $database, $mosConfig_live_site; $query = "SELECT * FROM #__events WHERE state =1 ORDER BY publish_up RAND() LIMIT 1"; $database->setQuery( $query ); $rows = $database->loadObjectList(); ?> <img src="<?= $mosConfig_live_site .'/images/events/'.$rows->images ?>" class="thumbimages"> <br><br> <?php } show_latest_banner(); ?> i am getting an error and i dont know exactly how to fix it. this is the error i am getting Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /var/www/html/spa/modules/mod_events_banner.php on line 120 hope you could help me fix this. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/104167-solved-need-help-on-random-select/ Share on other sites More sharing options...
GingerRobot Posted May 5, 2008 Share Posted May 5, 2008 The # is the mysql comment character - anything following is taken to be a comment. You should avoid giving your databases,tables or fields names with special characters or reserved words. You can get around the problem by placing the table name in backticks(`), but it would be better to change the table name. $query = "SELECT * FROM `#__events` WHERE state =1 ORDER BY publish_up RAND() LIMIT 1"; Quote Link to comment https://forums.phpfreaks.com/topic/104167-solved-need-help-on-random-select/#findComment-533285 Share on other sites More sharing options...
pixeltrace Posted May 5, 2008 Author Share Posted May 5, 2008 i solve the problem already. thanks! this is the code that i used <? function show_latest_banner() { global $database, $mosConfig_live_site; $query = "SELECT id FROM #__events WHERE state =1 ORDER BY RAND() LIMIT 1"; $database->setQuery($query); $id = $database->loadResult(); $query = "SELECT images FROM #__events WHERE id =$id"; $database->setQuery($query); $image = $database->loadResult(); ?> <a href="index.php?option=com_events&task=event_details&id=<? echo $id ?>&Itemid=78"><img src="<?= $mosConfig_live_site .'/images/events/'.$image ?>" class="thumbimages"></a> <?php } show_latest_banner(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/104167-solved-need-help-on-random-select/#findComment-533297 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.