Jump to content

Recommended Posts

Hello, I'm a pawn coder from the modification SA-MP (( http://www.sa-mp.com )) so please excuse me if I don't understand something. Anyways, I am trying to get the person with the most kills in the whole database, and display it. How can I do that? This is what I have so far:

 

mysql_query("SELECT * FROM users ORDER BY kills");

Link to comment
https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/
Share on other sites

Might want to post your code then.

<?php 
$host "xx.xx.xx.xx" // Blocked for safety
$user "x"  // Blocked for safety
$password "x"  // Blocked for safety
$db "x" // Blocked for safety
mysql_connect($host,$user,$password);
mysql_selectdb($db);
mysql_query("SELECT * FROM users ORDER BY Kills DESC LIMIT 1");

?>

 

Obviously I blocked all the regular stuff with x's. Check out my code and tell me what's wrong.  :shrug:

 

Strangly I managed to fix it. Now how would I make it show:

 

$msg = mysql_query("SELECT * FROM users ORDER BY Kills DESC LIMIT 1");
echo $msg;

 

Like that?

 

Well, you'd normally place it into a variable so you can go over the rows:

$q =  mysql_query("SELECT * FROM users ORDER BY Kills DESC LIMIT 1");

while($row = mysql_fetch_array($q)){ 
       echo '<pre>';
       echo print_r($row);
}

 

That can give you a better idea of what you're doing.

Strangly I managed to fix it. Now how would I make it show:

 

$msg = mysql_query("SELECT * FROM users ORDER BY Kills DESC LIMIT 1");
echo $msg;

 

Like that?

 

Well, you'd normally place it into a variable so you can go over the rows:

$q =  mysql_query("SELECT * FROM users ORDER BY Kills DESC LIMIT 1");

while($row = mysql_fetch_array($q)){ 
       echo '<pre>';
       echo print_r($row);
}

 

That can give you a better idea of what you're doing.

 

nothing wont show up

 

You don't need a while loop because your only selecting one row.

 

<?php 
$host "xx.xx.xx.xx" // Blocked for safety
$user "x"  // Blocked for safety
$password "x"  // Blocked for safety
$db "x" // Blocked for safety
mysql_connect($host,$user,$password);
mysql_select_db($db);
if ($result = mysql_query("SELECT * FROM users ORDER BY Kills DESC LIMIT 1")) {
  if (mysql_num_rows($result)) {
    $row = mysql_fetch_array($result);
    print_r($row);
  } else {
    echo "No results found";
  }
} else {
  trigger_error(mysql_error());
}
?>

You don't need a while loop because your only selecting one row.

 

<?php 
$host "xx.xx.xx.xx" // Blocked for safety
$user "x"  // Blocked for safety
$password "x"  // Blocked for safety
$db "x" // Blocked for safety
mysql_connect($host,$user,$password);
mysql_select_db($db);
if ($result = mysql_query("SELECT * FROM users ORDER BY Kills DESC LIMIT 1")) {
  if (mysql_num_rows($result)) {
    $row = mysql_fetch_array($result);
    print_r($row);
  } else {
    echo "No results found";
  }
} else {
  trigger_error(mysql_error());
}
?>

 

Now only ?> is showing on the web page.. (( Bug? ))

Is your server configured to parse php? It would appear not.

 

what?

 

We're wondering why it would display the PHP source in the first place. Are you viewing the file directly on web browser by chance?

(IE: C:\files\this.php)

 

And as well, is it .php? Web servers are not really configured to run them off default extensions like .phtml etc.

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.