Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.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
在屏幕上显示PHP搜索结果_Php_Postgresql - Fatal编程技术网

在屏幕上显示PHP搜索结果

在屏幕上显示PHP搜索结果,php,postgresql,Php,Postgresql,我已经编写了一个php搜索页面,但是我在解决我想要的页面显示问题时遇到了困难 我的数据返回查询是正确的,我相信我的问题是如何在屏幕上显示信息 示例表 userid Questionnaire ID QID Question Answer 1 38 846 Question 1 Answer 1 1 38 849 Questi

我已经编写了一个php搜索页面,但是我在解决我想要的页面显示问题时遇到了困难

我的数据返回查询是正确的,我相信我的问题是如何在屏幕上显示信息

示例表

userid    Questionnaire ID      QID     Question        Answer 
  1        38                   846     Question 1      Answer 1
  1        38                   849     Question 2      Answer 2
  1        38                   850     Question 3      Answer 3
  1        38                   869     Question 4      Answer 4
  2        38                   846     Question 1      Answer 1
  2        38                   849     Question 2      Answer 2
  2        38                   850     Question 3      Answer 3
  2        38                   869     Question 4      Answer 4
我想展示什么

userid
1
Questionaire ID
38
Question 1
Answer 1
Question 2
Answer 2
Question 3
Answer 3
Question 4
Answer 4
PAGE BREAK (if possible)
userid
2
Questionaire ID
38
Question 1
Answer 1
Question 2
Answer 2
Question 3
Answer 3
Question 4
Answer 4
我得到的是这个

userid
1
Questionaire ID
38
Question 1
Answer 1
userid
1
Questionaire ID
38
Question 2
Answer 2
userid
1
Questionaire ID
38
Question 3 etc


userid
2
Questionaire ID
38
Question 1
Answer 1
userid
2
Questionaire ID
38
Question 2
Answer 2
userid
2
Questionaire ID
38
Question 3 etc
我相信我必须使用foreach数组才能在互联网上进行搜索,但我对PHP和自学还不熟悉,因此很难理解它的工作方式。 我就是这样回应我的结果的

while ($row = pg_fetch_array($result)) {


echo '<div style="border:1px solid #000000; padding:15px; margin-bottom: 10px;">';
echo '<p><strong>User ID:</strong><br> ' . $row['userid'] . '</p>';
echo '<p><strong>Questionaire ID:</strong><br> ' . $row['Questionaire ID'] . '</p>';
echo '<p><strong>Question:</strong><br> ' . $row['Question'] . '</p>';
echo '<p><strong>Answer:</strong><br> ' . $row['Answer'] . '</p>';
echo '</div>';
while($row=pg\u fetch\u数组($result)){
回声';
echo'用户ID:
'.$row['userid'..

'; 回显“问卷ID:
”.$row['Questionaire ID'.

”; 回显“问题:
”.$row['Question'.

”; 回显“答案:
”.$row[“答案]。

”; 回声';

抱歉,我更新了我的帖子,使其更加清晰

将结果存储在一个数组中,然后将其打印到屏幕上

//I have never seen pg_fetch_array()
while($row = mysql_fetch_assoc($result)){
  $new_arr[] = $row;
}
//print each row
foreach($new_arr as $new){
  echo $new;
}
试试看


用户ID
问卷ID
QID
问题:
答复

我们的服务器使用postgres,因此我主要在PHP.net上研究发现pg_fetch_数组,您的方法是我需要如何返回数据,但在我的头撞到表上两天后,我无法让它工作。我知道,因为我回显了我的查询,这显示在我的页面上,但我的PHP在此之后就停止了f youtube视频,阅读了无数页面,包括这里,但没有一个页面能说明我正在尝试做什么。你介意给我展示一下这个示例吗?@Gazzo1967到底是什么问题?我对php不熟悉,从我的示例中,我想显示我的结果,因为我对php不熟悉,我无法正确实现数组和foreach。这s是我在php页面上运行的脚本中的错误警告:为foreach()提供的参数无效在第115行的/var/www/site/site/forms/application_search.php中,行数:26。从我的示例中,我想将我的结果显示为用户1,问卷ID,然后是问题1,答案,问题2,答案2。取而代之的是用户1,问卷ID,问题1,答案1,然后是下一行用户1,问卷ID,问题2,答案2。我是一个视觉学习者从示例中学习,除非我做错了,否则这将返回我已经拥有的内容。问答列有多行,与1个用户ID相关。列QID是每个问题的变量
<table>
  <tr>
    <th>userid</th>
    <th>Questionnaire ID</th>
    <th>QID</th>
    <th>Question</th>
    <th>Answer</th>
  </tr>
  <?php
    while ($row = pg_fetch_array($result)) {
     echo '<tr>';
     echo '<th>'.$row['userid'].'</th>';
     echo '<th>'.$row['Questionaire ID'].'</th>';
     echo '<th>'.$row['QID'].'</th>';
     echo '<th>'.$row['Question'].'</th>';
     echo '<th>'.$row['Answer'].'</th>';
     echo '</tr>'
    ?>
</table>