Jump to content

ORDER BY = random?


gdfhghjdfghgfhf

Recommended Posts

hmmm that site you gave me won't work

 

 

can you give me an example how i could randomize this query? It's currently ordered by ids

 

$f5 = "$bbuserinfo[field5]";
$query = "SELECT * FROM quebec_userfield WHERE field5='$f5' ORDER BY userid DESC";
$res = mysql_query($query) or die(mysql_error());  
while($row = mysql_fetch_array($res)) { 
$id = $row["userid"];

$query = "SELECT username, userid FROM quebec_user WHERE userid=$id ORDER BY userid DESC";
$res = mysql_query($query) or die(mysql_error());  
while($row = mysql_fetch_array($res)) { 
$nom = $row["username"];
echo "<a href=\"member.php?username=$nom\">";
echo $nom;
echo "</a><br>";
}

}

Link to comment
Share on other sites

strange, try www.php.net/shuffle

 

also - try this:

 

while($row = mysql_fetch_array($res)) { 
   $res[] = $row;
}
shuffle($res);
foreach($res As $row){
$id = $row["userid"];

$query = "SELECT username, userid FROM quebec_user WHERE userid=$id ORDER BY userid DESC";
$res = mysql_query($query) or die(mysql_error());  
while($row = mysql_fetch_array($res)) { 
$nom = $row["username"];
echo "<a href=\"member.php?username=$nom\">";
echo $nom;
echo "</a><br>";
}

 

may be long way around but should work.

Link to comment
Share on other sites

Opps i missed an ending parenthesis, try this:

 

$f5 = "$bbuserinfo[field5]";
$query = "SELECT * FROM quebec_userfield WHERE field5='$f5' ORDER BY userid DESC";
$res = mysql_query($query) or die(mysql_error());  
while($row = mysql_fetch_array($res)) { 
   $res[] = $row;
}
shuffle($res);
foreach($res As $row){
$id = $row["userid"];

$query = "SELECT username, userid FROM quebec_user WHERE userid=$id ORDER BY userid DESC";
$res = mysql_query($query) or die(mysql_error());  
while($row = mysql_fetch_array($res)) { 
$nom = $row["username"];
echo "<a href=\"member.php?username=$nom\">";
echo $nom;
echo "</a><br>";
}
}

 

replace the last code you gave me with this.

 

hope this helps,

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.