I've two tables:
1. practices_areas(areaID, area_name, description).
2. attorney_profiles(attorneyID, firstname, lastname, email, password, biography, areas_servicing, photo).
The attorneys fill in a form to save their individual profiles. The area_name from practice_areas makes checkboxes for the filed areas_servicing in attorney_profiles table.
The code to do this is as follows:
<b>Practice Areas:</b> <br>
<?php
$sql1 = mysql_query("SELECT areaID, area_name FROM practice_areas ORDER BY area_name");
while($row1 = mysql_fetch_array($sql1))
{
echo '<input type="checkbox" name="areas_servicing[]" value="'.$row1['area_name'].'" />'.$row1['area_name']."<br />";
}
?>
The above code makes checkboxes for each area_name in the practice_areas table.
Now, when the attorneys check the areas and click submit, it inserts the checkbox values into the areas_servicing field with a comma separator. The code for inserting is as follows:
PHP Code:
$practice_ids = implode(',', $_POST['areas_servicing']);
if( !empty($_POST) )
{
$sql = "INSERT INTO attorney_profiles (firstname,lastname,email,password,biography,practice_areas,photo) VALUES ('$firstname','$lastname','$email','$password','$biography','$practice_ids','{$_FILES['photo']['name']}')";
}
Suppose i check appeals and criminal law with ids 2 and 5 then then above code adds 2, 5 into the areas_servicing in the attorney_profiles table. and these ids come from the practice_areas table.
Then for updating i've a query which updates the checkbox values, but when the form is first seen it doesn't show the checkbox values as checked.
Here is the code:
<b>Practice Areas:</b> <br>
<?php
$practice_query = mysql_query("SELECT areaID, area_name FROM practice_areas ORDER BY area_name");
while($data = mysql_fetch_assoc($practice_query))
{
$areaID = $data['areaID'];
$area_name = $data['area_name'];
if(strpos($data['area_name'], $data['areaID']) !== FALSE)
{
$checked = 'checked="checked" ';
}
else
{
$checked = '';
}
echo '<input type="checkbox" name="practice_areas[]" value="'.$data['area_name'].'"'. $checked .' />'.$data['area_name']."<br>\n";
}
?>
The above code should be showing the checked boxes as checked, but it doesn't work.
The code for updating is as follows:
$practice_ids = implode(', ', $_POST['practice_areas']);
$sql = "UPDATE attorney_profiles SET firstname='". $firstname ."', lastname='". $lastname ."', email='". $email ."', biography='". $biography ."', practice_areas='". $practice_ids ."', photo='". $_FILES['photo']['name'] ."' WHERE attorneyID='".$_POST[attorneyID]."'";
it updates the checkboxes. for e.g, if i update from appeals to suppose business law, it will update the 2 to 4, which r again the ids of those area_name.
How do i retrieve the actual area_name instead of those ids which are stored corresponding to the area_names.
For e.g., if my profile has areas_servicing column as 2, 5. My profile on the public pages should show up the actual names corresponding to these ids from the practice_areas table.
Also, if someone clicks on an area_name, it should show up all the attorneys servicing that area.