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.

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

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助