我希望有一行名为“'see'的列,然后此列将具有默认值no值或”yes“值。
所以..
我已经尽了最大努力实现它,但它无法正常工作。我认为我解决这个问题的逻辑可能不正确?
include 'DB.php';
$con = mysqli_connect($host,$user,$pass);
$dbs = mysqli_select_db($databaseName, $con);
// Grabs one row where it hasn't been seen before
$query = mysqli_query("SELECT number, association, image_file, skeleton, sound, colour, comments FROM num_image WHERE seen='' ORDER by rand() LIMIT 1");
// Updates the above row with the 'seen' column saying 'yes''
$query = mysqli_query("UPDATE num_image SET seen = yes");
// Fetches Result
$thestuff = mysqli_fetch_row($query);
$seenme=$_POST['seen']; // get value of 'seen' column
$result = mysqli_query("SELECT * FROM num_image where seen=$seenme");
// Trying to delivery a message if the enitre 'seen' column is ALL yes.
while($row = mysqli_fetch_row($result))
{
if($row['seen'] == 'yes')
{ // All numbers seen
echo 'You have successfully completed all numbers.';
echo json_encode($thestuff);
}
else
{ // Show numbers
echo json_encode($thestuff);
}
}
SELECT和UPDATE行是否也必须是if语句? 干杯
答案 0 :(得分:1)
您必须转义更新语句中的值:
$query = mysqli_query("UPDATE num_image SET seen = 'yes' ");