有人可以完成此查询以连接sql

时间:2021-07-21 04:56:31
   <?php
$servername = "localhost";
$username = "*******";
$password = "******";
$dbname = "*****";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
} 


$sql = "EXPLAIN select created_at, user_id, power, sum(btc) Earnings\n"
    . "from btcs\n"
    . "group by user_id\n"
    . "order by user_id";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
     // output data of each row
     while($row = $result->fetch_assoc()) {
         echo "<br> id: ". $row["user_id"]. " - Name: ". $row["user_id,"]. " " . $row["btc"] . "<br>";
     }
} else {
     echo "0 results";
}

$conn->close();
?>  

Kindly Solve this issue please..

请解决这个问题..

and simple query and its work great in phpmyadmin but i dont know how to write in php page with complete dababase connection.

和简单的查询及其在phpmyadmin中的工作很棒,但我不知道如何在完整的dababase连接的php页面中编写。

$sql = "select created_at, user_id, power, sum(btc) Earnings\n"
    . "from btcs\n"
    . "group by user_id\n"
    . "order by user_id LIMIT 0, 30 ";

2 个解决方案

#1


0  

You should try debugging. Try this:

你应该尝试调试。试试这个:

$sql = "EXPLAIN select created_at, user_id, power, sum(btc) Earnings FROM btcs GROUP BY user_id ORDER BY user_id";

$result = $conn->query($sql);

if (!$conn->error) {
   printf("Errormessage: %s\n", $conn->error);   // Check if your SQL has any syntax error
}

#2


-1  

You should write this

你应该写这个

    <?php
    $servername = "localhost";
    $username = "*******";
    $password = "******";
    $dbname = "*****";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
         die("Connection failed: " . $conn->connect_error);
    } 


$sql = "EXPLAIN select created_at, user_id, power, sum(btc) Earnings FROM btcs GROUP BY user_id ORDER BY user_id";

    $result = $conn->query($sql);

if (!$conn->error) {
   printf("Errormessage: %s\n", $conn->error);
}

    if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
             echo "<br> id: ". $row["user_id"]. " - Name: ". $row["user_id,"]. " " . $row["btc"] . "<br>";
         }
    } else {
         echo "0 results";
    }

    $conn->close();
    ?>

#1


0  

You should try debugging. Try this:

你应该尝试调试。试试这个:

$sql = "EXPLAIN select created_at, user_id, power, sum(btc) Earnings FROM btcs GROUP BY user_id ORDER BY user_id";

$result = $conn->query($sql);

if (!$conn->error) {
   printf("Errormessage: %s\n", $conn->error);   // Check if your SQL has any syntax error
}

#2


-1  

You should write this

你应该写这个

    <?php
    $servername = "localhost";
    $username = "*******";
    $password = "******";
    $dbname = "*****";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
         die("Connection failed: " . $conn->connect_error);
    } 


$sql = "EXPLAIN select created_at, user_id, power, sum(btc) Earnings FROM btcs GROUP BY user_id ORDER BY user_id";

    $result = $conn->query($sql);

if (!$conn->error) {
   printf("Errormessage: %s\n", $conn->error);
}

    if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
             echo "<br> id: ". $row["user_id"]. " - Name: ". $row["user_id,"]. " " . $row["btc"] . "<br>";
         }
    } else {
         echo "0 results";
    }

    $conn->close();
    ?>