I tried to follow along with the mymismatch script in chapter 8 but for some reason I appear to be getting a weird error and I don't understand why that might be
The errors appear to be related to this block of code:
// Compare each response and calculate a mismatch total $score = 0; $topics = array(); for ($i = 0; $i < count($user_responses); $i++) { if ($user_responses[$i]['response'] + $mismatch_responses[$i]['response'] == 3) { $score += 1; array_push($topics, $user_responses[$i]['topic_name']); } }Here's the rest of the code for some greater context:
[code]
// Start the session
require_once('startsession.php');
// Insert the page header
$page_title = 'Where opposites attract!';
require_once('header.php');
require_once('appvars.php');
require_once('connectvars.php');
// Show the navigation menu
require_once('navmenu.php');
// Only look for a mismatch if the user has questionnaire responses stored
$query = "SELECT * FROM mismatch_response WHERE user_id = '" . $_SESSION['user_id'] . "'";
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
or die(DB_CONNECT_ERR . mysqli_connect_error() . DB_CONNECT_ERR_NO . mysqli_connect_errno());
$data = mysqli_query($dbc, $query)
or die( SQL_SELECT_ERR . mysqli_error($dbc) . SQL_ERR_NO . mysqli_errno($dbc) . QUERY_USED . $query );
if (mysqli_num_rows($data) != 0) {
// First grab the user's response from the response table (JOIN to get the topic name)
$query = "SELECT mr.response_id, mr.topic_id, mr.response, mt.name AS topic_name " .
"FROM mismatch_response AS mr " .
"INNER JOIN mismatch_topic AS mt " .
"USING (topic_id) " .
"WHERE mr.user_id = '" . $_SESSION['user_id'] . "'";
$data = mysqli_query($dbc, $query)
or die( SQL_SELECT_ERR . mysqli_error($dbc) . SQL_ERR_NO . mysqli_errno($dbc) . QUERY_USED . $query );
$user_responses = array();
while ($row = mysqli_fetch_array($data)) {
array_push($user_responses, $row);
}
// Initialize the mismatch results
$mismatch_score = 0;
$mismatch_user_id = -1;
$mismatch_topics = array();
// Loop through the user table comparing other people's responses to the user's response
$query = "SELECT user_id FROM mismatch_user WHERE user_id != '" . $_SESSION['user_id'] . "'";
$data = mysqli_query($dbc, $query)
or die( SQL_SELECT_ERR . mysqli_error($dbc) . SQL_ERR_NO . mysqli_errno($dbc) . QUERY_USED . $query );
while ($row = mysqli_fetch_array($data)) {
// Grab the response data for the user (a potential mismatch)
$query2 = "SELECT response_id, topic_id, response FROM mismatch_response " .
"WHERE user_id = '" . $row['user_id'] . "'";
$data2 = mysqli_query($dbc, $query2);
$mismatch_responses = array();
while ($row2 = mysqli_fetch_array($data2)) {
array_push($mismatch_responses, $row2);
}
}
// Compare each response and calculate a mismatch total
$score = 0;
$topics = array();
for ($i = 0; $i < count($user_responses); $i++) {
if ($user_responses[$i]['response'] + $mismatch_responses[$i]['response'] == 3) {
$score += 1;
array_push($topics, $user_responses[$i]['topic_name']);
}
}
// Check to see if this person is better than the best mismatch so far
if ($score > $mismatch_score) {
// We found a better mismatch, so update the mismatch search results
$mismatch_score = $score;
$mismatch_score = $score ;
$mismatch_user_id = $row['user_id'];
$mismatch_topics = array_slice($topics, 0);
}
}
// Make sure a mismatch was found
if ($mismatch_user_id != -1) {
$query = "SELECT username, first_name, last_name, city, state, picture from mismatch_user " .
"WHERE user_id = '$mismatch_user_id'";
$data = mysqli_query($dbc, $query)
or die( SQL_SELECT_ERR . mysqli_error($dbc) . SQL_ERR_NO . mysqli_errno($dbc) . QUERY_USED . $query );
if (mysqli_num_rows($data) == 1) {
// The user row was found, so display the user data
$row = mysqli_fetch_array($data);
echo '';
if (!empty($row['first_name']) && !emtpy($row['last_name'])) {
echo $row['first_name'] . ' ' . $row['state'] . '
';
}
echo '';
if (!empty($row['picture'])) {
echo '%27%20.%20MM_UPLOAD_PATH%20.%20$row[%27picture%27]%20.%20%27
';
}
echo '';
// Display the mismatched topics
echo '<h4>View












