Jump to content

Random mysql query


cordoprod

Recommended Posts

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.