I'm learning PHP (and jQuery this week) here for a class, and I'm confused about how to proceed with the format we have been provided. The assignment is a CRUD resume application.
The following code is in a PHP file to add work experience positions by year and description:
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;
}
What the code above looks to be doing is retrieving the positions added as an array.
The following code is a second PHP file that simply displays the data:
<?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;
?>
How do I make the connection between the loadPos function and the view page? It's not just a matter of echoing loadPos()?
I need to print this array in a as well. Do I need to make a second prepare statement in my view page?
This is a piece of the 'add' code for field names:
$('#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>');
Any help is appreciated. Thank you in advance.