Estoy teniendo un problema con esta función y me da este problema
Código:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/a9937565/public_html/HeadFirst/C8/questionnaire.php on line 32
El código que tengo es este
Código PHP:
//If this user has never answered the questionnaire, insert empty responses into the database
$query = "SELECT * FROM mismatch_response WHERE user_id = '" . $_SESSION['user_id'] . "'";
$data = mysqli_query($dbc, $query);
if(mysqli_num_rows($data) == 0) {
//First grab the list of topic IDs from the topic table
$query = "SELECT topic_id FROM mismatch_topic ORDER BY category_id, topic_id";
$data = mysqli_query($dbc, $query);
$topicIDs = array();
while($row = mysqli_fetch_array($data)) {
array_push($topicIDs, $row['topic_id']);
}
//Insert empty response rows into the responsable table, one per topic
foreach($topicIDs as $topic_id) {
$query = "INSERT INTO mismatch_response (user_id, topic_id) VALUES ('" . $_SESSION['user_id'] . "', '$topic_id')";
mysqli_query($dbc, $query);
}
}
Y el problema dice que está en el while
Código PHP:
while($row = mysqli_fetch_array($data)) {
array_push($topicIDs, $row['topic_id']);
}
El error no sé porque me lo da en la función mysqli porque he estado comprobando y comparando en otras líneas donde uso esa función y está exactamente igual...
EDITO: Ya he encontrado la solución, el fallo estaba en el segundo SELECT, en vez de poner category he puesto category_id