Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7893057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:01:33+00:00 2026-06-03T07:01:33+00:00

SQL/PHP query works in PHPmyAdmin but not the site. I notice that many have

  • 0

SQL/PHP query works in PHPmyAdmin but not the site.

I notice that many have had this problem but admittedly I am not as advanced as some of the coders on this site…yet. =) I humbly request any experience you may have laying around 😛 Thank you.

<?php
// session_start();
// ob_start();

ini_set("display_errors", true);
error_reporting(-1);

// Connection to database.
mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db('') or die(mysql_error());
?>

<?php
// Maintenance page.

$maintenance = 1; // 1 = Site Online || 0 = Site Offline 

if ($maintenance == 0) {
    ?>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <head>
            <style type="text/css">
                body {
                    color:#ffffff;
                    background-color: #000000;
                    font-family: Arial, Helvetica, sans-serif;
                }
            </style>
        </head>
        <title></title>
    </head>
    <body>  
    <center><img src="images/p4flogo.png" /></center><br /> 
    <?php
    echo "<br/><br /><center>This site is currently under maintenance.</center>";
} else {

// Start of main website.
    ?>
<html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <head>
            <style type="text/css">
                body {
                    color:#ffffff;
                    background-color: #000000;
                    font-family: Arial, Helvetica, sans-serif;
                }    
                a:link {color: orange; text-decoration: underline; }
                a:active {color: red; text-decoration: underline; }
                a:visited {color: orange; text-decoration: underline; }
                a:hover {color: red; text-decoration: none; }
                table { 
                    border-color: #333333;
                }
                th { 
                    background-color:#ffffff;
                    color:#000000;
                    font-family: Arial, Helvetica, sans-serif; 
                    height:30px;
                }
                td { font-family: Arial, Helvetica, sans-serif; 
                     color:#ffffff;
                     height:35px;
                }
            </style>
        </head>
        <title></title>
    </head>
    <body>
        <table border="0" cellspacing="1" align="center">
            <tr><td>
            <center><img src="images/p4flogo.png" /></center><br /><br />
            <form action="" method="post">
                Search for a soldier: <input type="text" name="value" size="35" /><input type="submit" value="search" /><br />
                <?php
                if (isset($_POST['value']) && !empty($_POST['value'])) {
                    $value = mysql_real_escape_string($_POST['value']);
                    // query to database for soldier stats
                    // query works in phpmyadmin but not on site.
                         $sql = "
                               SELECT
                                `Name`,
                                 MAX(`Level`),
                                `Class`,
                                 SUM(`Kills`),
                                 SUM(`Deaths`),
                                 SUM(`Points`),
                                 SUM(`TotalTime`),
                                 SUM(`TotalVisits`),
                                 `CharacterID`
                               FROM
                                 `Characters`
                               WHERE
                                 `Name` LIKE '$value%' OR `CharacterID` LIKE '$value'
                               GROUP BY
                                 `Name`,
                                 `Class`,
                                 `CharacterID`
                               ORDER BY
                                 `Name` ASC;";
                    $query = mysql_query($sql);
                    $numrow = mysql_num_rows($query);
                    if ($numrow >= 1) {
                        echo "<br /><a href=\"index.php\"><b>View TOP 100 Players!</b></a><br />";
                        echo "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">  ";
                        echo "<th>Soldier Name</th><th>Level</th><th>Class</th><th>KDR</th><th>Kills</th><th>Deaths</th><th>Points</th><th>Hours Played</th><th>Total Visits</th><th>CharacterID</th>";

                        echo "<br />";
                        WHILE ($row = mysql_fetch_assoc($query)) {

                            $SoldierName = $row['Name'];
                            $Level = $row['Level'];
                            $Class = $row['Class'];
                            if ($Class == NULL | empty($Class)) {
                                $Class = '<center>n / a</center>';
                            }
                            if ($Class == 1) {
                                $Class = 'Assault';
                            }
                            if ($Class == 2) {
                                $Class = 'Recon';
                            }
                            if ($Class == 3) {
                                $Class = 'Medic';
                            }
                            if ($Class == 4) {
                                $Class = 'Engineer';
                            }
                           echo $Kills = $row['Kills'];
                              if ($Kills == 0) {
                                  $Kills = 1;
                              }
                            $Deaths = $row['Deaths'];
                            if ($Deaths == 0) {
                                $Deaths = 1;
                            }
                            $Kdr = round($Kills / $Deaths, 2);
                            $Points = $row['Points'];

                            $TimePlayed = $row['TotalTime'];
                            if ($TimePlayed == 0) {
                                $TimePlayed = 1;
                            } else {
                                $TimePlayed = round(($TimePlayed / 3600), 0);
                            }

                            $TotalVisits = $row['TotalVisits'];
                            $CharacterID = $row['CharacterID'];

                            echo "<tr>";
                            echo "<td><b>$SoldierName</b></td>";
                            echo "<td>$Level</td>";
                            echo "<td>$Class</td>";
                            if ($Kdr > 3.9) {
                                echo "<td><font color=\"red\"><b>$Kdr</b></font></td>";
                            } else if ($Kdr > 2.5 && $Kdr < 4) {
                                echo "<td><font color=\"orange\"><b>$Kdr</b></font></td>";
                            } else {
                                echo "<td><font color=\"limegreen\">$Kdr</font></td>";
                            }
                            echo "<td>$Kills</td>";
                            echo "<td>$Deaths</td>";
                            echo "<td>$Points</td>";
                            echo "<td>$TimePlayed</td>";
                            echo "<td>$TotalVisits</td>";
                            echo "<td>$CharacterID</td>";
                            echo "</tr>";
                        }
                        echo "</table>";
                    } else {
                        echo "No player found with that name. Please try again.";
                    }
                } else {
                    if (empty($_POST['value'])) {
                        echo "<font color=\"red\">You must enter a search value.</font>";
                    }
                    // query to p4f database for top 100 players.
                    $sql = "SELECT * FROM `Characters` WHERE `Points` > 1 GROUP BY `Name` ORDER BY `Points` DESC LIMIT 100;";
                    $query = mysql_query($sql);
                    echo "<h3>TOP 100 PLAYERS</h3>";
                    echo "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">  ";
                    echo "<th></th><th>Soldier Name</th><th>Level</th><th>Class</th><th>KDR</th><th>Kills</th><th>Deaths</th><th>Points</th><th>Hours Played</th><th>Total Visits</th><th>CharacterID</th>";
                    // echo "Made it to loop!";
                    $Rank = 1;
                    WHILE ($row = mysql_fetch_assoc($query)) {

                        $SoldierName = $row['Name'];
                        $Level = $row['Level'];
                        $Class = $row['Class'];
                        if ($Class == NULL | empty($Class)) {
                                $Class = '<center>n / a</center>';
                            }
                        if ($Class == 1) {
                            $Class = 'Assault';
                        }
                        if ($Class == 2) {
                            $Class = 'Recon';
                        }
                        if ($Class == 3) {
                            $Class = 'Medic';
                        }
                        if ($Class == 4) {
                            $Class = 'Engineer';
                        }
                        $Kills = $row['Kills'];
                        if ($Kills == 0) {
                            $Kills = 1;
                        }
                        $Deaths = $row['Deaths'];
                        if ($Deaths == 0) {
                            $Deaths = 1;
                        }
                        $Kdr = round($Kills / $Deaths, 2);
                        $Points = $row['Points'];

                        $TimePlayed = $row['TotalTime'];
                        if ($TimePlayed == 0) {
                            $TimePlayed = 1;
                        } else {
                            $TimePlayed = round(($TimePlayed / 3600), 0);
                        }

                        $TotalVisits = $row['TotalVisits'];
                        $CharacterID = $row['CharacterID'];

                        echo "<tr>";
                        echo "<td>$Rank</td>";
                        echo "<td><b>$SoldierName</b></td>";
                        echo "<td>$Level</td>";
                        echo "<td>$Class</td>";
                        if ($Kdr > 3.9) {
                            echo "<td><font color=\"red\"><b>$Kdr</b></font></td>";
                        } else if ($Kdr > 2.5 && $Kdr < 4) {
                            echo "<td><font color=\"orange\"><b>$Kdr</b></font></td>";
                        } else {
                            echo "<td><font color=\"limegreen\">$Kdr</font></td>";
                        }
                        echo "<td>$Kills</td>";
                        echo "<td>$Deaths</td>";
                        echo "<td>$Points</td>";
                        echo "<td>$TimePlayed</td>";
                        echo "<td>$TotalVisits</td>";
                        echo "<td>$CharacterID</td>";
                        echo "</tr>";
                        $Rank++;
                    }
                    echo "</table>";
                }
            }
            ?>
            </td></tr>             
    </table>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:01:35+00:00Added an answer on June 3, 2026 at 7:01 am

    I’m not sure about MySQL, but I know that in SQL when you do an aggregate function, like SUM(Kills), then you can’t reference the row via $row[‘kills’]. I don’t know if this is your problem, but you could try doing SUM(Kills) as ‘kills’ in your SELECT statement. Doing this for your aggregate SELECTs will allow you to reference them all this way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with a query that works in phpmyadmin but not with
using php, i have a sql query which works fine, dateentry only has the
I have a problem with sql query in php: select user, name, outlet, switch,
I have a strange problem, I'm sending an SQL query through PHP: INSERT INTO
I am running a sql in PHP query that is dieing with the mysql_error()
I'm writing a PHP script that builds an SQL query by concatenating the string
I have three files: one called sql.php witch has a class db that I
I using sql in php, but, result not show: test(id, name, type, category_id); and
I have a mysql table like this (sql): CREATE TABLE IF NOT EXISTS silver_and_pgm
I have a very weird problem while trying to pass and SQL query using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.