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
Php 在单独的文件中从PDO输出列表_Php_Jquery - Fatal编程技术网

Php 在单独的文件中从PDO输出列表

Php 在单独的文件中从PDO输出列表,php,jquery,Php,Jquery,我在这里学习PHP(本周还有jQuery)是为了上课,我对如何继续使用我们提供的格式感到困惑。该作业是CRUD简历申请 以下代码位于PHP文件中,用于按年份和说明添加工作经验职位: function loadPos($pdo, $profile_id) { $stmt = $pdo->prepare('SELECT * FROM Position WHERE profile_id = :prof ORDER BY rank'); $stmt->execute(array( ':pro

我在这里学习PHP(本周还有jQuery)是为了上课,我对如何继续使用我们提供的格式感到困惑。该作业是CRUD简历申请

以下代码位于PHP文件中,用于按年份和说明添加工作经验职位:

function loadPos($pdo, $profile_id) {
$stmt = $pdo->prepare('SELECT * FROM Position WHERE profile_id = :prof ORDER BY rank');
$stmt->execute(array( ':prof' => $profile_id));
$positions = array();
while ( $row = $stmt->fetch(PDO::FETCH_ASSOC)){
    $positions[] = $row;
}
return $positions;
}

上面的代码看起来要做的是检索作为数组添加的位置

以下代码是仅显示数据的第二个PHP文件:

<?php

        $stmt = $pdo->prepare("SELECT * FROM profile where profile_id = :xyz");
        $stmt->execute(array(":xyz" => $_GET['profile_id']));
        if ( $stmt === false ) {
            $_SESSION['error'] = 'Bad value for profile_id';
            header( 'Location: index.php' ) ;
            return;
        }

        while ( $row = $stmt->fetch(PDO::FETCH_ASSOC)) {

            echo "First Name: ";
            echo(htmlentities($row['first_name']));
            echo "<br /><br />";
            echo "Last Name: ";
            echo(htmlentities($row['last_name']));
            echo "<br /><br />";
            echo "Email: ";
            echo(htmlentities($row['email']));
            echo "<br /><br />";
            echo "Headline: ";
            echo(htmlentities($row['headline']));
            echo "<br /><br />";
            echo "Summary: ";
            echo(htmlentities($row['summary']));
            echo "<br /><br />";

        }

        echo '<p><a href="index.php">Done</a>';
            //return;

    ?>

如何在loadPos功能和查看页面之间建立连接?这不仅仅是响应loadPos()的问题

我还需要打印一个数组。我是否需要在我的查看页面中做第二个prepare语句

这是字段名的一段“添加”代码:

$('#position_fields').append(
            '<div id="position'+countPos+'") \
            <p>Year: <input type="text" name="year'+countPos+'" value="" /> \
            <input type="button" value="-" \
                onclick="$(\'#position'+countPos+'\').remove();return false;"></p> \
            <textarea name="desc'+countPos+'" rows="8" cols="80"></textarea>\
            </div>');
$(“#位置_字段”)。追加(

'只需调用函数,只需提供连接变量即可。我能够提取数据,但不是通过连接。配置文件id总是缺失,我不知道调用函数时如何进行此操作。此时,我可以看到数据,但数据以双精度显示。每个条目都会回显两次。。