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条)

报告相同问题?

悬赏问题

  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。