Let's look at the code and let me clarify what's going on for you...
//Start by opening the PHP tags :P
<?php
//These 2 lines say "if the form is not submitted, do this..."
if (!isset($_POST['submit']))
{
What are we told to do? Start the form - as I said in my earlier post, this action=" " can either be a specific file name, or as Devine seems to suggest, the same file itself, you can call this using $_SERVER['PHP_SELF']
echo '<form action="" method="POST">';
Here comes the loop. I prefer while() loops myself, but this does it too - Devine could explain why he chose this particular method. This basically creates 10 checkboxes, each with a name (profiles) which puts stuff in the profiles[] array. I assume you'll be pulling this from the database? In which case, you'll want to put some db connection stuff and a query before you start the table. But anyway, this loop creates the contents of the form 🙂
for ($i = 1; $i <= 10; $i++)
{
echo '<input type="checkbox" name="profiles[]" value="' . $i . '"> profile #' . $i . '<br>';
}
OK, now we've got the contents, lets close the form and give it a 'submit' button
echo '
<input type="submit" name="submit" value="submit">
</form>
';
} //NB - this curly bracket is closing the if(!isset) statement from the top
So essentially, this page (called whatever you like) has two actions - what to do it the form is NOT submitted - ie what it should do when it's initially loaded(above) and what to do after, if the form HAS been submitted (below).
else
{ //start the 'else' part of the if-else construction
So, the form has been submitted - check that there's some content in the submission:
if (isset($_POST['profiles']))
{
ok there is content - let's use it in the query:
$sql = 'SELECT * FROM Candidates, CandidateProfiles WHERE Candidate.CandidateID = CandidateProfiles.CandidateID AND CandidateProfiles.ProfileID IN(' . implode(',', $_POST['profiles']) . ')';
I didn't look at the code properly before - this is why you're seeing the SQL
echo $sql;
So to display the results, you just need to say something along the lines of:
//start the table BEFORE the while loop, else you'll end up with a lot of tables :)
<table>
while $row=mysql_fetch_assoc($sql)
{
echo '<tr><td>'.$row['candidateid'].'</td><td>'.$row['profileid'].'</td></tr>';
} //this ends the while() loop
So now we've said what to do if there ARE items in the submitted form, let's end the if() statement, and say what to do if the user hasn't checked anything:
}
else
{
echo 'you did not check any profiles';
}
}
?>
Hope this all makes sense, and apologies if I appear to be teaching my granny to suck eggs 🙂