Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.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
Javascript PHP&;PostgreSQL:如何显示数据库中与用户相关的数据?_Javascript_Php_Html_Css_Postgresql - Fatal编程技术网

Javascript PHP&;PostgreSQL:如何显示数据库中与用户相关的数据?

Javascript PHP&;PostgreSQL:如何显示数据库中与用户相关的数据?,javascript,php,html,css,postgresql,Javascript,Php,Html,Css,Postgresql,我有一个登录区域,它通向我的项目,在那里用户可以在表中写入计算。此表应保存输入,以便只有登录的用户才能看到其数据。现在我的问题是,怎么做?在execute中必须写入什么?foreach发布数据是否正确? 我准备了一份声明: $sth = $dbh->prepare("SELECT * FROM calculations WHERE user_id = registered_users.user_id"); $sth->execute(array($_SESSION['user_id'

我有一个登录区域,它通向我的项目,在那里用户可以在表中写入计算。此表应保存输入,以便只有登录的用户才能看到其数据。现在我的问题是,怎么做?在execute中必须写入什么?foreach发布数据是否正确? 我准备了一份声明:

$sth = $dbh->prepare("SELECT * FROM calculations WHERE user_id = registered_users.user_id");
$sth->execute(array($_SESSION['user_id'], $date, $startkm, ...)); 
$calculations = $sth->fetchAll();
和我的PHP代码:

<?php foreach($calculations as $calculation) : ?>
                    <tr>
                        <td><?php echo $calculations->date ?></td>
                        <td><?php echo $calculations->startkm ?></td>
                        ...
                    </tr>
                <?php endforeach; ?>
            </table>

我假设
$\u会话['user\u id']
包含注册用户的
用户id

<?php
$sth = $dbh->prepare("SELECT * FROM calculations WHERE user_id = ?");
$sth->execute(array($_SESSION['user_id'])); 
$calculations = $sth->fetchAll();
?>


我非常确定这个
从user\u id=registed\u users的计算中选择*。user\u id“
无法工作否,因为我需要execute语句中的参数,但我不知道这些参数。您应该在该查询中传递某种
id
。发布数据库架构以获取更多帮助
创建表计算(user_id INT NOT NULL引用注册用户(user_id),calc_id串行主键NOT NULL,date VARCHAR(25)NOT NULL,…)
在您的问题中发布此信息
<?php
$sth = $dbh->prepare("SELECT * FROM calculations WHERE user_id = ?");
$sth->execute(array($_SESSION['user_id'])); 
$calculations = $sth->fetchAll();
?>