SA-MP Forums

Go Back   SA-MP Forums > Other > Everything and Nothing

Reply
 
Thread Tools Display Modes
Old 06/05/2016, 07:41 PM   #11
Kyle
High-roller
 
Join Date: Mar 2009
Location: United Kingdom
Posts: 2,260
Reputation: 333
Default Re: [MySQL + PHP] Top 10 Players

Quote:
Originally Posted by [rG]Cold View Post
How exactly,Kyle?
I don't use it personally or had any real hand experience but this tutorial seems easy enough:

https://www.youtube.com/watch?v=lwo4fAqaVFM
__________________
Kyle is offline   Reply With Quote
Old 07/05/2016, 01:07 PM   #12
BlackBank
Gangsta
 
Join Date: Dec 2010
Location: The Netherlands
Posts: 522
Reputation: 437
Default Re: [MySQL + PHP] Top 10 Players

Quote:
Originally Posted by iZN View Post
if($row_count > 0) { ... }
There is no need to use a > 0 check. 0 and everything lesser is always false, and everything above 0 is always true in PHP (Also the same as in PAWN and a lot of other programming languages).
BlackBank is offline   Reply With Quote
Old 07/05/2016, 03:08 PM   #13
iZN
High-roller
 
Join Date: Jun 2010
Posts: 2,369
Reputation: 569
Default Re: [MySQL + PHP] Top 10 Players

Quote:
Originally Posted by BlackBank3 View Post
There is no need to use a > 0 check. 0 and everything lesser is always false, and everything above 0 is always true in PHP (Also the same as in PAWN and a lot of other programming languages).
I see. I just found something about this in PHP, it is converting the variable to a boolean value. I think I never tried this out before, thanks for the info.

The false thing is different for some languages, like -1 is also true in C, etc. So you're just wrong there.
__________________
iZN is offline   Reply With Quote
Old 07/05/2016, 06:20 PM   #14
BlackBank
Gangsta
 
Join Date: Dec 2010
Location: The Netherlands
Posts: 522
Reputation: 437
Default Re: [MySQL + PHP] Top 10 Players

Quote:
Originally Posted by iZN View Post
I see. I just found something about this in PHP, it is converting the variable to a boolean value. I think I never tried this out before, thanks for the info.

The false thing is different for some languages, like -1 is also true in C, etc. So you're just wrong there.
Sorry, my fault, you are right about the -1 and lesser values.
BlackBank is offline   Reply With Quote
Old 07/05/2016, 08:19 PM   #15
KevinReinke
Banned
 
Join Date: May 2016
Posts: 100
Reputation: 13
Default Re: [MySQL + PHP] Top 10 Players

Quote:
Originally Posted by iZN View Post
...
if(!$variable) = 0 = false
if($variable) = not 0 = true

The row count will never go below 0.
KevinReinke is offline   Reply With Quote
Old 07/05/2016, 09:24 PM   #16
[rG]Cold
Huge Clucker
 
[rG]Cold's Avatar
 
Join Date: Aug 2012
Posts: 234
Reputation: 35
Default Re: [MySQL + PHP] Top 10 Players

So,did anyone here manage to make a proper working top 10 system? I'd like to see people sharing their creations and thoughts!
[rG]Cold is offline   Reply With Quote
Old 07/05/2016, 09:29 PM   #17
[KHK]Khalid
Gangsta
 
[KHK]Khalid's Avatar
 
Join Date: Jan 2012
Location: Alexandria, Egypt
Posts: 854
Reputation: 136
Default Re: [MySQL + PHP] Top 10 Players

Quote:
Originally Posted by [rG]Cold View Post
So,did anyone here manage to make a proper working top 10 system? I'd like to see people sharing their creations and thoughts!
Did you manage to get stats to update automatically or do you still need help with that?
[KHK]Khalid is offline   Reply With Quote
Old 08/05/2016, 12:35 AM   #18
KevinReinke
Banned
 
Join Date: May 2016
Posts: 100
Reputation: 13
Default Re: [MySQL + PHP] Top 10 Players

Quote:
Originally Posted by [rG]Cold View Post
So,did anyone here manage to make a proper working top 10 system? I'd like to see people sharing their creations and thoughts!
connection.php
PHP Code:
<?php
    $database_host 
"localhost";
    
$database_user "root";
    
$database_pass "";
    
$database_db "dw_top_10_players";

    
$connection = new PDO("mysql:host=$database_host;dbname=$database_db;charset=utf8"$database_user$database_pass);
    
$connection -> setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
?>
style.css
PHP Code:
body
{
    
width100%;

    
background#FFFFFF;

index.php
PHP Code:
<?php
    
include_once 'includes/connection.php';
?>

<meta http-equiv = "Content-Type" content = "text/html; charset=utf-8"/>

<link rel = "stylesheet" href = "style/style.css"/>

<style>
    div.b_section_1
    {
        background: #FFFFFF;
    }
</style>

<html>
    <head>
        <title>
            Top 10 Players
        </title>
    </head>

    <body>
        <div class = "b_section_1">
            <?php

            $query 
$connection -> prepare("SELECT `name`, `score` FROM `players` ORDER BY `score` DESC LIMIT 10");

            if(
$query -> execute())
            {
                if(
$query -> rowCount())
                {
                    
$count 0;

                    
?>

                    <table style = "background: #EEEEEE; border: 1px solid #000000;">
                        <tr>
                            <td style = "padding: 5px; border: 1px solid #000000; font-family: arial; font-weight: bold;">
                                Position
                            </td>

                            <td style = "padding: 5px; border: 1px solid #000000; font-family: arial; font-weight: bold;">
                                Player
                            </td>

                            <td style = "padding: 5px; border: 1px solid #000000; font-family: arial; font-weight: bold;">
                                Score
                            </td>
                        </tr>

                        <?php

                        
while($query_result $query -> fetch())
                        {
                            
?>

                            <tr>
                                <td style = "padding: 5px; border: 1px solid #000000; font-family: arial;">
                                    <?php

                                    
echo ++ $count;

                                    
?>
                                </td>

                                <td style = "padding: 5px; border: 1px solid #000000; font-family: arial;">
                                    <?php

                                    
echo $query_result['name'];

                                    
?>
                                </td>

                                <td style = "padding: 5px; border: 1px solid #000000; font-family: arial;">
                                    <?php

                                    
echo number_format($query_result['score']);

                                    
?>
                                </td>
                            </tr>

                            <?php
                        
}

                        
?>
                    </table>

                    <?php
                
}
                else
                {
                    echo 
'No players were found.';
                }
            }

            
?>
        </div>
    </body>
</html>
sql file
PHP Code:
-- phpMyAdmin SQL Dump
-- version 4.5.1
-- http://www.phpmyadmin.net
--
-- 
Host127.0.0.1
-- Generation TimeMay 082016 at 02:39 AM
-- Server version10.1.13-MariaDB
-- PHP Version5.6.20

SET SQL_MODE 
"NO_AUTO_VALUE_ON_ZERO";
SET time_zone "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- 
Database: `dw_top_10_players`
--

-- --------------------------------------------------------

--
-- 
Table structure for table `players`
--

CREATE TABLE `players` (
  `
idint(11NOT NULL,
  `
namevarchar(24NOT NULL,
  `
scoreint(11NOT NULL
ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- 
Dumping data for table `players`
--

INSERT INTO `players` (`id`, `name`, `score`) VALUES
(1'Player_1'50),
(
2'Player_2'20),
(
3'Player_3'500),
(
4'Player_4'2),
(
5'Player_5'232),
(
6'Player_6'6543),
(
7'Player_7'1024),
(
8'Player_8'4021),
(
9'Player_9'468),
(
10'Player_10'2056),
(
11'Player_11'700),
(
12'Player_12'45),
(
13'Player_13'603),
(
14'Player_14'436),
(
15'Player_15'900),
(
16'Player_16'260);

--
-- 
Indexes for dumped tables
--

--
-- 
Indexes for table `players`
--
ALTER TABLE `players`
  
ADD PRIMARY KEY (`id`);

--
-- 
AUTO_INCREMENT for dumped tables
--

--
-- 
AUTO_INCREMENT for table `players`
--
ALTER TABLE `players`
  
MODIFY `idint(11NOT NULL AUTO_INCREMENTAUTO_INCREMENT=17;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */
output
KevinReinke is offline   Reply With Quote
Old 08/05/2016, 08:24 AM   #19
[rG]Cold
Huge Clucker
 
[rG]Cold's Avatar
 
Join Date: Aug 2012
Posts: 234
Reputation: 35
Default Re: [MySQL + PHP] Top 10 Players

This is what me and my friend UnKnowN112 came up with (btw I'm Mattaffix): LIVE DEMO
[rG]Cold is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] [FS] Top 10 Players MySQL lukitaxxx_samp Filterscripts 12 08/04/2014 05:03 PM
MySQL - Players Get Same Stats Camacorn Scripting Help 3 03/08/2012 09:52 AM
TOP 'X' Players SQL to MySQL - Help nGen.SoNNy Scripting Help 1 05/05/2012 08:01 AM
[MySQL] Top 10 Players maxi459 Scripting Help 2 30/10/2011 04:49 PM
TOP Players in MYSQL? Ricop522 Scripting Help 2 13/10/2011 02:42 AM


All times are GMT. The time now is 10:05 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.