With my current project, I use PHP & MySQL database to talk to the game app, and I’m stuck with this PHP script problem. I scoured the web, but most of the sites simply solves more complex query problem, and maybe my problem is too simple for anyone not to find a solution and no need for any help. But hey, I admit defeat, and I’d so appreciate any help trouble-shooting this thing.
What I’m trying to do is to select a row with the least value from a table and update the flag column for that row. But it’s not working for me. If I break it into two queries, it works, but combining the two isn’t going anywhere. What am I doing wrong?
Naomi
[Edit: space added to the script]
THIS WORKS AND DO THE JOB:
$flag = 1;
$query = "SELECT MIN(value) FROM ". $myTable;
$data = mysqli\_query($dbh, $query);
$dataSet = mysqli\_fetch\_row($data);
$value = $dataSet[0];
$queryUpdate = "UPDATE ". $myTable . " SET flag='" . $flag . "' WHERE value='" . $value. "'";
$dataUpdate = mysqli\_query($dbh, $queryUpdate);
BUT I WANT TO COMBINE THESE SELECT QUERY AND UPDATE QUERY TO A SINGLE QUERY, but none of the following works. What am I doing wrong?
--Attempt #1a:
$flag = 1;
$query = "UPDATE ". $myTable . " SET flag='" . $flag . "' WHERE value=( SELECT MIN(value) )";
$data = mysqli\_query($dbh, $query);
--Attempt #1b (removed single quotes):
$flag = 1;
$query = "UPDATE ". $myTable . " SET flag=" . $flag . " WHERE value=( SELECT MIN(value) )";
$data = mysqli\_query($dbh, $query);
--Attempt #2a:
$flag = 1;
$query = "UPDATE ". $myTable . " SET flag='" . $flag . "' WHERE value=( SELECT MIN(value) FROM '". $myTable . "')'";
$data = mysqli\_query($dbh, $query);
--Attempt #2b (removed single quotes):
$flag = 1;
$query = "UPDATE ". $myTable . " SET flag=" . $flag . " WHERE value=( SELECT MIN(value) FROM ". $myTable . ")";
$data = mysqli\_query($dbh, $query);
--Attempt #3a:
$flag = 1;
$query = "UPDATE ". $myTable . " SET flag='" . $flag . "' ORDER BY value ASC LIMIT 1";
$data = mysqli\_query($dbh, $query);
--Attempt #3b(removed single quotes):
$flag = 1;
$query = "UPDATE ". $myTable . " SET flag=" . $flag . " ORDER BY value ASC LIMIT 1";
$data = mysqli\_query($dbh, $query);
[import]uid: 67217 topic_id: 32713 reply_id: 332713[/import]
