Jump to content

MAX Count im Stumped....


Dethman

Recommended Posts

<?php
if($player['raceID']==1){
$q = "select `username` from `user_users` where vote_count=(SELECT MAX(`vote_count`) FROM `user_users` where `raceID`='1')";
$leader = mysql_query($q) or trigger_error(mysql_error());
if( $leader ){
echo($leader);
}
else{
echo('None');
}

}
if($player['raceID']==2){
$q = "select `username` from `user_users` where vote_count=(SELECT MAX(`vote_count`) FROM `user_users` where `raceID`='2')";
$leader = mysql_query($q) or trigger_error(mysql_error());
if( $leader ){
echo($leader);
}
else{
echo('None');
}
}
if($player['raceID']==3){
$q = "select `username` from `user_users` where vote_count=(SELECT MAX(`vote_count`) FROM `user_users` where `raceID`='3')";
$leader = mysql_query($q) or trigger_error(mysql_error());
if( $leader ){
echo($leader);
}
else{
echo('None');
}
}
if($player['raceID']==4){
$q = "select `username` from `user_users` where vote_count=(SELECT MAX(`vote_count`) FROM `user_users` where `raceID`='4')";
$leader = mysql_query($q) or trigger_error(mysql_error());
if( $leader ){
echo($leader);
}
else{
echo('None');
}
}
?>

 

 

For Some reason this is not working right it displayes this

 

 

Resource id #9 

 

Please Help... :'(

 

Link to comment
https://forums.phpfreaks.com/topic/113892-max-count-im-stumped/
Share on other sites

After doing a mysql_query, you have to use one of the mysql_fetch functions to actually get the data.

 

For example:

<?php
if($player['raceID']==1){
      $q = "select `username` from `user_users` where vote_count=(SELECT MAX(`vote_count`) FROM `user_users` where `raceID`='1')";
      $leader = mysql_query($q) or trigger_error(mysql_error());
      if(mysql_num_rows($leader) > 0 ){
   $rw = mysql_fetch_assoc($leader);
          echo $rw['username'];
      }
      else{
   echo 'None';
     }
}
?>

 

Ken

}

Link to comment
https://forums.phpfreaks.com/topic/113892-max-count-im-stumped/#findComment-585231
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.