dongwei1921 2018-01-23 09:29
浏览 148
已采纳

Wordpress数据库连接插件

I made a kind of plugin just for the database connection it works but if i activate my plugin the page wil go a little bit down so actually my site will become ugly

 $servername = "xxxx";  // naam of ip van de machine ... 127.0.0.1
          $username = "xxxx";  //naam van gebruiker
          $password = "xxxx"; // wachtwoord
          $dbname = "xxxx"; //db naam
          $conn = mysqli_connect($servername, $username, $password, $dbname);
          if (!$conn) {
            die("Connection failed: " . mysqli_connect_error());
        }
                    if (isset($_GET["code"]) )
    {
    $code = $_GET['code'];
    }
    else
    {
        $code = '';
    }
    //$naam = '%DR%';

    //$sql = "SELECT * FROM docenten WHERE naam=\"$naam\"";
    $sql = "SELECT * FROM `cadeaubon` WHERE Kortingscode like \"$code\"";

    //echo $sql; //debuggen
    echo "<BR>";

    $result = mysqli_query($conn, $sql);

    if (mysqli_num_rows($result) > 0) {
        // output data of each row
        echo "<table>";
        while($row = mysqli_fetch_assoc($result)) {
            echo "- ID: " . $row["ID"]. " - Kortingscode: " . $row["Kortingscode"]. " - Aantal personen: " . $row["AantPersonen"] . " - Naam: " . $row["Naam"] . " -  Achternaam: " . $row["Achternaam"] . " - Leeftijd: " . $row["Leeftijd"] . " - Datum: " . $row["Datum"]."<br>";
        }
        echo "</table>";
    } else {
        echo "";
    }

    mysqli_close($conn);

this is my code and i thought maybe it will help if the result will display at the bottom of the page but i dont know how

  • 写回答

1条回答 默认 最新

  • dongmen1860 2018-01-23 09:56
    关注

    I guess you left there <br> from your debug echo:

    //echo $sql; //debuggen
    echo "<BR>";
    

    However I don't know where in code this gets executed and how it integrates with WordPress. If the following table is shown inside content area of the page, the <br> shouldn't affect your site design other than pushing the table one line down.

    It also seems to be a bit of overkill to create your own database connection - I would think WordPress already is connected and it would be preferable to use its own connection, unless it is a completely different database.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程