Friday 1 July 2016

PHP MySQLi Passing text value of select or querying for it

I have a USERS table that stores both User ID's (users.uid) and a full name (users.full_name). Then I have an On Call schedule table that lists all weeks for the next year along with the a name field and user id (uid) field for each on-call shift slot (say day & night). The on call





on_call_week,us_night_uid,us_night_full_nam,us_day_uid,us_day_full_name



17-12-25, 53, Jane Doe, 94, Jill Todd17-12-18, 2342, John Smith, 24, Bob Orr




I then have a form that lists all on call week start dates (with check boxes next to them) and a submit button on that goes to a page that lists a form with every selected on call week with drop downs both on call slots (day night)



What I'm trying to figure out his how to update both the UID field and the full_name field when only the value of the drop down list boxes is passed (the value being the UID's and the text being the full_names).




Should I be trying (in some way) to pass the text of the select drop downs? If not should I just make a two new queries inside the FOR loop to grab the day and night slot full_names for each UID. Or, should I be trying to do something like querying the whole user table into an array and then looping through that array twice per FOR loop pass to get the matching names for the two UID slots?



One thing I don't understand about MySQLi that I'm having trouble finding an answer for is if you loop through a mysqli_fetch_array multiple times, does the query get remade or can you loop through the $result multiple times without the query being remade to the db (while($row = mysqli_fetch_array($result)) )? I'm still pretty new to PHP and honestly not even sure how to visually see how many times PHP queries a database verses using a temporary copy(?) of the result set.



I was following this old guide on how to build a form for updating more than one record at a time based on which records are checked.



Thanks for any help.



$dbname = "on_call";

include '../shared_recources/db_connect.php';

if(isset($_POST["submit"]) && trim($_POST["submit"]) != "")
{
$checked_weeks = count($_POST["selected_on_call_weeks"]);

for($i=0; $i<$checked_weeks; $i++)
{
$us_day_uid = $_POST["us_day_uid"][$i];
$us_night_uid = ($_POST["us_night_uid"][$i];


mysqli_query($con, "UPDATE on_call.on_call_schedule
SET us_day_full_name = '" . $_POST["us_day_full_name"][$i] . "',
us_day_uid = '?????????',
us_night_full_name = '" . $_POST["us_night_full_name"][$i] . "',
us_night_uid = '" '???????????????' . "',
WHERE id = '" . $_POST["selected_on_call_weeks"][$i] . "'

");
}

}
?>

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...