douduan1953 2015-09-22 12:18
浏览 49
已采纳

如何回显MySQL表列中的内容

I have for some time tried to create a admin panel view of things where a user can insert things to then get posted on the website. Kind of a smaller version of wordpress, right now mostly for private and educational use. However, I can't get it to post the content that is sent to the database from the adminpanel view of things. It won't display anything at all, which makes me think I am doing something critically wrong.

This is what I got : (Connection)

   <?php
session_start();

$adress = 'Host adress goes here';
$dbusername = 'Database username goes here';
$dbpassword = 'Database password goes here';

$anslutning = mysqli_connect($host, $dbusername, $dbpassword);
if (!$anslutning) die ("<br /><b>Can't connect to server</b>");

$anslutning->select_db('Database name goes here') or die ("Could not connect to database");

    ?>

And the code I currently can't get to work

<p class="welcometext">
    <?php

        $getContentQuery = "SELECT content FROM tblPages";

        if ($getContent = $anslutning->prepare($getContentQuery)) {



        $getContent->execute();
        $result = $anslutning->query($getContentQuery);

        while ($rows = mysql_fetch_array($result)) {

            echo $rows[2];


        }
    }




    ?>
</p>

**EDIT:**I just realised it does not echo out anything inside the if statement, so as a newbie to PHP I'm not sure if it is supposed to do so, or if this is why 'while' is not working.

EDIT2: So I have gotten my answer and ticket it. However, I need to add something to it. While what I had written was wrong from the beginning, removing all earlier PHP code seemed to fix the problem (Let the troubleshooting commence!). I appreciate everyones help and time, and as long as i can figure what is breaking it, the issue is solved.

  • 写回答

2条回答 默认 最新

  • douzhuang1900 2015-09-22 12:56
    关注
     if ($getContent = $anslutning->prepare($getContentQuery)) {
         $getContent->execute();
         $content='';
         $getContent->bind_result($content);
         while ($getContent->fetch()) {
            echo $content;
         }
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?