Attempting to SELECT, reduce by 1 then UPDATE with php/mysql -
just trying find value of table field , reduce 1 using mysql via php?
is there simple way this?
below code not process...
cheers, j
<?php $conn = connecttodb(); /* declare remaining integer */ settype($screenings, "integer"); /* select current screenings value , assign remaining variable */ $findquery("select screenings screener_users user_id = '" . $userid . "';"); $screenings = $conn->query($findquery); /* reduce value 1 */ $screenings--; /* update screener_users new value */ $updatequery = "update screener_users set screenings = '" . $screenings . "' user_id = '" . $userid . "';"; $result = $conn->query($updatequery); ?>
you making mistake on query call. can see @ documentation , returns pdostatement, should call resultset value want. should work:
<?php $conn = connecttodb(); settype($screenings, "integer"); $findquery("select screenings screener_users user_id = '" . $userid . "';"); foreach ($conn->query($findquery) $row) { $screenings = $row[0]; $screenings--; $updatequery = "update screener_users set screenings = '" . $screenings . "' user_id = '" . $userid . "';"; $result = $conn->query($updatequery); } ?>
now calling query executed , saying should resultset of wich row , assing $row
while iterating on it. there, call first column of query's return ($row[0]
) , rest of job.
Comments
Post a Comment