Sunday, 8 September 2013

Displaying bit datatype from mysql query as a set of radio buttons

Displaying bit datatype from mysql query as a set of radio buttons

Ok searched here and many many sites on Google results for this but can't
find an exact fix for my issue.
I have a sql pulling a name and an office. So it goes something like this:
$sql = "SELECT myStaff_tbl.firstName, myStaff_tbl.lastName,
myOffice_tbl.officeName,
myOfficeLoc_tbl.primary_loc_bit
FROM myOfficeLoc_tbl
INNER JOIN myOffice_tbl ON myOfficeLoc_tbl.office_Id =
myOffice_tbl.office_Id
INNER JOIN myStaff_tbl ON myOfficeLoc_tbl.staff_Id = myStaff_tbl.staff_Id
WHERE location_tbl.staffID = $myvariable"
And my html looks like this:
<td align="center"><input type="radio" name="bit_primary_loc" value=""
<?php if ($row_rs_myQuery['primary_loc_bit'] == 1) {echo
"checked='checked'";} ?> > </td>
of course my html is wrapped in a loop statement checking to see if there
is more than one office location associated with this staff member. If
there are multiple locations it will spit them out. But my problem at the
moment is just getting it to output the $row_rs_myQuery['primary_loc_bit']
right now when I try to var_dump the row or just simply echo that it shows
blank.
I want the radio button to be checked if that office is set as the staff
members primary location and because they can only have 1 primary location
it needs to be a radio button.
Any ideas why it wouldn't be showing as checked if it is indeed showing
when I run the sql query in my phpMyAdmin?
Just for reference I get something like this when I run the sql in my
phpMyAdmin
Steve Smith Portland 1
Steve Smith Salem 0
Steve Smith Ontario 0

No comments:

Post a Comment