Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQLite和PHP使用数组显示数据_Php_Sqlite - Fatal编程技术网

SQLite和PHP使用数组显示数据

SQLite和PHP使用数组显示数据,php,sqlite,Php,Sqlite,我想显示特定表格中的列,我做到了,但我对此一无所知,我正试图为我自己和我拥有的社区建立这个网站,这样他们就可以从通过发布获得的积分中兑换装备。脚本工作正常,但我想摆脱这个东西数组а和箭头,你们可以在我提供的屏幕截图上看到它,我只想显示用户名和点数,但不想显示全部内容 下面是我正在使用的代码: <?php $db = new SQLite3('phantombot.db'); $sql = "SELECT variable, value FROM phan

我想显示特定表格中的列,我做到了,但我对此一无所知,我正试图为我自己和我拥有的社区建立这个网站,这样他们就可以从通过发布获得的积分中兑换装备。脚本工作正常,但我想摆脱这个东西数组а和箭头,你们可以在我提供的屏幕截图上看到它,我只想显示用户名和点数,但不想显示全部内容

下面是我正在使用的代码:

<?php
        $db = new SQLite3('phantombot.db');

        $sql = "SELECT variable, value FROM phantombot_points";

        $result = $db->query($sql);//->fetchArray(SQLITE3_ASSOC);

        $row = array();

        $i = 0;

         while($res = $result->fetchArray(SQLITE3_ASSOC)){

             if(!isset($res['variable'])) continue;

              $row[$i]['variable'] = $res['variable'];
              $row[$i]['value'] = $res['value'];
              $i++;

          }

          print_r($row);
?>

您可以为此创建表格

<table>
    <tr><th>Username</th><th>Points</th></tr>
      <?php  foreach($row as $datum): ?>
            <tr>
                <td><?php echo $datum['variable'];?></td>
                <td><?php echo $datum['value'];?></td>
            </tr>
      <?php endforeach;?>
</table>

用户名点

所以基本上我所需要做的就是删除代码的最后几个部分,然后粘贴它?您需要在while方法之后粘贴它。删除
print\r($row)
并将答案粘贴到
打印\r
的位置,效果非常好!谢谢你,阿甘!很高兴我能帮忙。如果对您有效,请接受&upvote。谢谢