简体   繁体   English

mysqli_fetch_array不更新

[英]mysqli_fetch_array not updating

I have created a CMS system where you can create pages with a template system. 我创建了一个CMS系统,您可以在其中创建带有模板系统的页面。 Very simple and it works. 非常简单,可以正常工作。 I have a script on the admin interface that makes a list of all the created pages (at the same time that they link to the respective edit page), but the script is not working correctly: It shows the pages I created by manual insertion of data in the PHPmyadmin but not the ones that I created via CMS system. 我在管理界面上有一个脚本,该脚本列出了所有已创建页面的列表(同时它们链接到相应的编辑页面),但是该脚本无法正常工作:它显示了我通过手动插入创建的页面数据在PHPmyadmin中,但不是我通过CMS系统创建的数据。

I've already checked the database and the pages I created using my CMS system are there. 我已经检查了数据库,并找到了使用CMS系统创建的页面。 Anyone can spot the mistake? 任何人都可以发现错误? Thanks in advance! 提前致谢!

<?php
    require_once "../scripts/conector.php";

    if (!$_GET['pid']) {
    $pageid = '1';
    } else {
        $pageid = preg_replace('/[^0-9]/', "", $_GET['pid']); // filter everything but numbers for security
    }

    $sqlCommand = "SELECT id, producent FROM pages WHERE showing='1' ORDER BY id ASC"; 
    $query = mysqli_query($myConnection, $sqlCommand) or die('Error: ' . mysqli_error($myConnection)); 

    $producentnamn = '';
    while ($row = mysqli_fetch_array($query)) { 
        $pid = $row["id"];
        $producent = $row["producent"];
        $producentnamn .= '<a href="edit_page.php?pid=' . $pid . '">' . $producent . '</a>';
    } 
    mysqli_free_result($query);
?>

<ul class="f-dropdown" id="drop1">
   <li><?php echo $producentnamn; ?></li>
</ul>

You have done mistake here, that outside while your trying to fetch var's value, so you have to save it in one array, like this 您在这里做错了,在尝试获取var的值时在外面,所以您必须将其保存在一个数组中,如下所示

$arr=array();
while ($row = mysqli_fetch_array($query)) { 
        $pid = $row["id"];
        $producent = $row["producent"];
        $producentnamn .= '<a href="edit_page.php?pid=' . $pid . '">' . $producent . '</a>';
       $arr[]=$producentnamn;
    } 
    mysqli_free_result($query);

now try to fetch this, 现在尝试获取它,

print_r($arr);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM