eazyefolife Posted January 14, 2010 Share Posted January 14, 2010 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"); Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/ Share on other sites More sharing options...
trq Posted January 14, 2010 Share Posted January 14, 2010 mysql_query("SELECT * FROM users ORDER BY kills DESC LIMIT 1"); Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994702 Share on other sites More sharing options...
eazyefolife Posted January 14, 2010 Author Share Posted January 14, 2010 mysql_query("SELECT * FROM users ORDER BY kills DESC LIMIT 1"); Thank's for the fast reply but I get a error now: PHP Parse error: parse error in C:\Users\Eric\Desktop\phpdesigner_output_tmp.php on line 26 Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994704 Share on other sites More sharing options...
trq Posted January 14, 2010 Share Posted January 14, 2010 Might want to post your code then. Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994706 Share on other sites More sharing options...
eazyefolife Posted January 14, 2010 Author Share Posted January 14, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994708 Share on other sites More sharing options...
eazyefolife Posted January 14, 2010 Author Share Posted January 14, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994714 Share on other sites More sharing options...
oni-kun Posted January 14, 2010 Share Posted January 14, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994715 Share on other sites More sharing options...
eazyefolife Posted January 14, 2010 Author Share Posted January 14, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994720 Share on other sites More sharing options...
trq Posted January 14, 2010 Share Posted January 14, 2010 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()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994725 Share on other sites More sharing options...
eazyefolife Posted January 14, 2010 Author Share Posted January 14, 2010 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? )) Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994734 Share on other sites More sharing options...
trq Posted January 14, 2010 Share Posted January 14, 2010 Not a bug in the code, maybe a bug in your server. What do you see when you right click and view source? Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994738 Share on other sites More sharing options...
eazyefolife Posted January 14, 2010 Author Share Posted January 14, 2010 Not a bug in the code, maybe a bug in your server. What do you see when you right click and view source? just shows my code exactly from dreamweaver.. Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994740 Share on other sites More sharing options...
trq Posted January 14, 2010 Share Posted January 14, 2010 php and all? Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994746 Share on other sites More sharing options...
eazyefolife Posted January 14, 2010 Author Share Posted January 14, 2010 php and all? yes Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994751 Share on other sites More sharing options...
trq Posted January 14, 2010 Share Posted January 14, 2010 Is your server configured to parse php? It would appear not. Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994762 Share on other sites More sharing options...
eazyefolife Posted January 14, 2010 Author Share Posted January 14, 2010 Is your server configured to parse php? It would appear not. what? Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994780 Share on other sites More sharing options...
oni-kun Posted January 14, 2010 Share Posted January 14, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994784 Share on other sites More sharing options...
trq Posted January 14, 2010 Share Posted January 14, 2010 Is your server configured to parse php? It would appear not. what? In order to execute php code you need a server configured to execute php code. Is yours? Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994802 Share on other sites More sharing options...
eazyefolife Posted January 14, 2010 Author Share Posted January 14, 2010 Is your server configured to parse php? It would appear not. what? In order to execute php code you need a server configured to execute php code. Is yours? yes Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994808 Share on other sites More sharing options...
trq Posted January 14, 2010 Share Posted January 14, 2010 If you can see the php code in the browser it would appear it is not configured properly. As oni-kun asked, are you using the .php extension for this file? Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994809 Share on other sites More sharing options...
eazyefolife Posted January 14, 2010 Author Share Posted January 14, 2010 If you can see the php code in the browser it would appear it is not configured properly. As oni-kun asked, are you using the .php extension for this file? yes Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-994991 Share on other sites More sharing options...
trq Posted January 14, 2010 Share Posted January 14, 2010 Are you accessing the site via a url like http://localhost/filename.php ? Can you make a simple test file and place this in it? <?php phpinfo(); ?> What does that display? Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-995164 Share on other sites More sharing options...
eazyefolife Posted January 15, 2010 Author Share Posted January 15, 2010 Are you accessing the site via a url like http://localhost/filename.php ? Can you make a simple test file and place this in it? <?php phpinfo(); ?> What does that display? I dont understand? Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-995619 Share on other sites More sharing options...
Buddski Posted January 15, 2010 Share Posted January 15, 2010 What do you type into your browser to view your file... Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-995623 Share on other sites More sharing options...
eazyefolife Posted January 15, 2010 Author Share Posted January 15, 2010 What do you type into your browser to view your file... Firefox (( I also tried opening it with IE and OPERA )) Quote Link to comment https://forums.phpfreaks.com/topic/188424-who-has-the-highest-field/#findComment-995624 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.