ahh! its understandable;
This will need to be two separate calls to the db;
<?php
$conn = conn(); // db setup
$sql = "YOUR_ORIGINAL_SELECT_SQL LIMIT 1"; // select sql from above
$res = $conn->query($sql) or die( mysqli_error($conn) ); // execute sql
$res = $res->fetch_object(); // fetch object from returning row
$res = $res->num_rows > 0 ? $res->userpoints_count : false; // create clause to contiune
if( $res ) { // execute clause
$sql = "YOUR_ORIGINAL_UPDATE_SQL"; // update sql
$conn->query($sql) or die( mysqli_error($conn) ); // execute sql
$affected = $conn->affected_rows; // used if you want to know num rows affected
mysqli_close($conn); // close db connection
return $affected; // used if you want to return num rows affected
}else { // fail clause
mysqli_close($conn); // close db connection
return false; // return not true :)
}?>
It will probably be a bit harder to understand, as i do everything using mysqli;
but you will want to make two(2) query statements, i.. to get something and, ii.. to update that something;
the reason that i used the fetch_object() call is because there is no need (in my view) to run a while loop on something that we know we only have one row of, and additionally are only trying to get one value out of that row.
so once we get that particular "something to update", then we can begin running our update sql. to be programmatic-lly(?) correct, we need to make sure that our SELECT statement came back with something or we will run into errors on the UPDATE;
IF the "something to update" came back with <i>something</i> then we can create our WHERE clause;
YOU do NOT need to use `` symbols in THIS instance; there are particular instance where you MUST.
Example: If i created a column name desc (short for description) I would NOT be able to UPDATE, SELECT this column because desc is short for descending;
SELECT desc FROM useful_information;
SELECT desc FROM useful_information;
The first would fail, and the second would work;
I hope you find this mildly useful...