Hi all ... before I get to the code, I want to explain exactly what it does. Please bear with me, it will help me figure out what exactly to ask for help with 😛
Ok.
I have 2 database tables
1st is called hosts_locations -- it contains information about where the companies clients are advertising at - different businesses and such -- so, the 2 important fields here are: location_id (an auto-incremented ID for each location) and company_name, the actual name of the company.
2nd table is called clients_locations -- it contains only 3 fields... ID (auto-inc), client_id and location_id of the location they're advertising in.
The way I have my edit_client.php set up is:
Under locations, checkmark boxes are dynamically generated ... one for each possible location where the clients may advertise at. The checkbox has the company_name after it. Currently, there are four locations, so there are 4 checkboxes, each followed by a different location name.
I can checkmark any 4 of these boxes, as many or as few as I like.
On the processing page, the array of checkboxes is checked, and for each company I chose, it adds that company_id (or, location_id) to the client_locations table, along with the client ID, one per row.
So if I check boxes test company 1, test company 3, test company 4, my client_locations table now looks like this:
ID client_id location_id
1 1 1
2 1 3
3 1 4
Everything is fine at this point, and working great, but here's where I need some SERIOUS help.
The company I am trying to do this for wants, when they first open the client.php file, to see the boxes already checked if there is a record for it ... in other words, if client_id 1 is there along with location_id 4, test company 4 should already have a checkmark.
As my checkmark boxes are dynamically generated with a while loop, I have NO idea how I would write the code to verify if the box SHOULD be checked or should be empty, depending on what is inside client_locations table.
Thank you so much for reading all that, I had to explain it fully or I'd get lost myself... Here is my current code snip I am using. Please, I'd really appreciate it if smoeone could show me how to do this.
$result=mysql_query("SELECT * FROM host_locations");
$total=mysql_num_rows($result);
while ($row=mysql_fetch_array($result))
{
$id[]=$row['location_id'];
$name[]=$row['company_name'];
}
$i = 0;
while ($i<$total)
{
echo "<input type='checkbox' name='location[]' value=".$id[$i].">".$name[$i]."<br>";
$i++;
}