cordoprod Posted April 30, 2008 Share Posted April 30, 2008 Hi. I want to display a random mysql query. I have a function: function RandomUser() { $db = new DbConnector(); $db->connect(); $sql = "SELECT online FROM travek_userstats WHERE has_pic='true' ORDER BY RAND()"; $result = $db->query($sql); return $result; } I get it by using echo RandomUser(); What I get is just: Resource ID #4...or something like that. What have I done wrong? Link to comment https://forums.phpfreaks.com/topic/103531-random-mysql-query/ Share on other sites More sharing options...
zenag Posted April 30, 2008 Share Posted April 30, 2008 return $result["online"]; Link to comment https://forums.phpfreaks.com/topic/103531-random-mysql-query/#findComment-530128 Share on other sites More sharing options...
cordoprod Posted April 30, 2008 Author Share Posted April 30, 2008 Then it just appears like this in the source: .....images/pg/_small.jpg.... The username we're supposed to be between pg/ and _small Link to comment https://forums.phpfreaks.com/topic/103531-random-mysql-query/#findComment-530130 Share on other sites More sharing options...
zenag Posted April 30, 2008 Share Posted April 30, 2008 CAN U SHOW CODE? Link to comment https://forums.phpfreaks.com/topic/103531-random-mysql-query/#findComment-530132 Share on other sites More sharing options...
cordoprod Posted April 30, 2008 Author Share Posted April 30, 2008 <?PHP function RandomUser() { $db = new DbConnector(); $db->connect(); $sql = "SELECT * FROM travek_userstats WHERE has_pic='true' ORDER BY RAND()"; $result = $db->query($sql); return $result['online']; } ?> <html> <head> <title>Travek.tk</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="styles/main.css" rel="stylesheet" type="text/css"> <style type="text/css"> <!-- .style4 {color: #00CC00} --> </style> </head> <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><br> <table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td height="594" align="center" valign="middle"><table width="85%" border="0" cellspacing="1" cellpadding="2"> <tr> <td align="right"><img src="images/pg/<?PHP echo RandomUser(); ?>_small.jpg" width="147" height="120" border="1" class="smalluser_side"></td> </tr> Link to comment https://forums.phpfreaks.com/topic/103531-random-mysql-query/#findComment-530133 Share on other sites More sharing options...
zenag Posted April 30, 2008 Share Posted April 30, 2008 use mysql_fetch_array() after.. $result = $db->query($sql); Link to comment https://forums.phpfreaks.com/topic/103531-random-mysql-query/#findComment-530142 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.