My main question being, are 'foreign keys' a METHOD of referencing table data between tables by using a primary key as a reference, or is this some sort of option (or attribute) you must set within mysql when creating tables for it to properly work? For me, the book does not do a great job at explaining this and since it tells me to just dump the schema from the downloaded examples, I'm very unclear how this works.
I'm also unclear on arrays, the book mentions it but not does explain it fully. An array is a collection of data put into a variable?
Sometimes i find this book using code that is not explained, here is a snippet:
echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">';
echo '<p>How do you feel about each topic?</p>';
$category = $responses[0]['category_name'];
echo '<fieldset><legend>' . $responses[0]['category_name'] . '</legend>';
foreach ($responses as $response) {
// Only start a new fieldset if the category has changed
if ($category != $response['category_name']) {
$category = $response['category_name'];
echo '</fieldset><fieldset><legend>' . $response['category_name'] . '</legend>';
}
// Display the topic form field
echo '<label ' . ($response['response'] == NULL ? 'class="error"' : '') . ' for="' . $response['response_id'] . '">' . $response['topic_name'] . ':</label>';
echo '<input type="radio" id="' . $response['response_id'] . '" name="' . $response['response_id'] . '" value="1" ' . ($response['response'] == 1 ? 'checked="checked"' : '') . ' />Love ';
echo '<input type="radio" id="' . $response['response_id'] . '" name="' . $response['response_id'] . '" value="2" ' . ($response['response'] == 2 ? 'checked="checked"' : '') . ' />Hate<br />';
}
echo '</fieldset>';
echo '<input type="submit" value="Save Questionnaire" name="submit" />';
echo '</form>';
// Insert the page footer
require_once('footer.php');
so from the above script:
what exactly does the [0] within $responses[0]['category_name'] do? my browser complains about it as well:
Next..
if (isset($_POST['submit'])) {
// Write the questionnaire response rows to the response table
foreach ($_POST as $response_id => $response) {
$query = "UPDATE mismatch_response SET response = '$response' WHERE response_id = '$response_id'";
mysqli_query($dbc, $query);
}
echo '<p>Your responses have been saved.</p>';
}
From the above snippet
I have no idea what this is doing.. taking every piece of data from the post array, putting it into $response_id and into $reponse?? very confused
how about array_push?
array_push($topicIDs, $row['topic_id']);
}
This loops through the $data array, and for every $topicIDs it finds it places into the $row array under topic_id? I know it briefly explains array_push on page 449, but i'm still unclear as to how it works
Lastly, when i use the code provided at http://www.headfirstlabs.com/books/hfphp/ for the questionnaire.php, when I try to use this it does not list anything, i have attached an image with exactly what i see, and the current scheme of my database (had to change extension to .txt or else would not upload)
Any help would be greatly appreciated..
Attached File(s)
-
mismatchdb_current.txt (6.14K)
Number of downloads: 268













