Ik heb een interview waarbij ik e.e.a. aanvink. Dat wordt netjes weg geschreven. Dit wil ik koppelen aan de laatste participant id uit de participant tabel en iedere regel hier onder moet gekoppeld worden aan de itemid. die staat in de items tabel.
SELECT * FROM Participant WHERE id=(SELECT max(id) FROM Participant)
SELECT items.ID, items.items FROM items WHERE items.role="DE" AND items.categorie="Communication" ORDER BY items.items;
<?php include 'dbh.inc.php'; ?>
<?php
var_dump($_POST); //met $_POST wordt de array met de verschillende items getoond
foreach($_POST['items'] as $item) {
$query = "INSERT INTO interview (role, yes, no, question, comment, level, itemID, participantID)
VALUES ('DE', '".mysqli_real_escape_string($conn, $item['yes'])."',
'".mysqli_real_escape_string($conn, $item['no'])."',
'".mysqli_real_escape_string($conn, $item['question'])."',
'".mysqli_real_escape_string($conn, $item['comment'])."',
'".mysqli_real_escape_string($conn, $item['level'])."',
'11',
'22'
)";
mysqli_query($conn, $query);
echo "<br>Record toegevoegd! ($query)<hr>";
}
?>
[size=xsmall]Toevoeging op 07/09/2017 13:15:10:[/size]
De pagina waarmee ik dit script benader, bevat al een link naar het items.ID
<?php
$comment = "";
// connect to the database
$result = $conn->query('SELECT participant.ID, items.items, participant.yes, Participant.no, Participant.question, Participant.comment
FROM participant
RIGHT JOIN items ON participant.itemID=items.ID
WHERE items.role="DE" AND items.categorie="Communication"
ORDER BY items.items')
?>
<form method="post" action="../../include/func.participant.inc.php" onsubmit="refreshAndClose()">
<table>
<tr>
<!--<th></th>--><th>Items</th><th>Y</th><th>N</th><th>?</th><th>Comment</th><th>levels</th>
<?php
while ($row = mysqli_fetch_assoc($result)) {?>
</tr>
<tr>
<td>
<?php echo $row['items'] ?>
</td>
<td>
<input name="items[<?php echo $row['ID']; ?>][yes]" type="checkbox" value="yes" <?php if ($row['yes'] == "yes") echo "checked"; ?>/>
</td>
<td>
<input name="items[<?php echo $row['ID']; ?>][no]" type="checkbox" value="no" <?php if ($row['no'] == "yes") echo "checked"; ?>/>
</td>
<td>
<input name="items[<?php echo $row['ID']; ?>][question]" type="checkbox" value="question" <?php if ($row['question'] == "yes") echo "checked"; ?>/>
</td>
<td>
<textarea name="items[<?php echo $row['ID']; ?>][comment]" rows="1" cols="25" placeholder="comment"><?php echo $comment;?></textarea>
</td>
<td>
<select name="items[<?php echo $row['ID']; ?>][level]">
<option value="">Select...</option>
<option value="1">1. Starter</option>
<option value="2">2. Junior</option>
<option value="3">3. Intermediate</option>
<option value="4">4. Senior</option>
<option value="5">5. Expert</option>
<option value="6">6. Un Known</option>
<option value="7">7. Future</option>
<option value="8">8. Not relefant</option>
</select>
</td>
</tr>
<?php } ?>
</table>
<input type="submit" name="submit" value="Submit">
</form>