Your problem is more to do with the way you structured the code than anything else. There is also a problem with the way you have named the campaign checkboxes as there is no way to uniquely identify them.
You also have the problem (which I think it more what you were originally getting at) where you aren't actually looping over the sub query on every line, or resetting the internal cursor on the recordset.
Try this version:
Code:
<?php
$query_users = mysql_query("SELECT u.id, u.email, s.user_id, s.campaign_id FROM ml_users u LEFT JOIN ml_subscriptions s ON u.id = s.user_id");
$campaigns_row1 = mysql_query("SELECT * FROM ml_campaigns");
?>
<div align="center">
<h1>Manage Users</h1>
<form id="update_subscriptions" name="update_subscriptions" method="post" action="">
<table border="0" cellpadding="6" cellspacing="0" class="table-border">
<tr>
<td>Email</td>
<?php
while ($c_data = mysql_fetch_array($campaigns_row1))
{
$c_id = $c_data['id'];
$c_name = $c_data['name'];
$c_desc = $c_data['description'];
?>
<td><?php echo $c_name; ?></td>
<?php
}
?>
</tr>
<?php
while ($user_data = mysql_fetch_array($query_users))
{
$user_id = $user_data['id'];
$email = $user_data['email'];
$camp_id = $user_data['campaign_id'];
$camp_user_id = $user_data['user_id'];
?>
<tr>
<td><?php echo $email; ?></td>
<?php
mysql_data_seek($campaigns_row1, 0);
while ($c_data = mysql_fetch_array($campaigns_row1))
{
$c_id = $c_data['id'];
?>
<td><input type="checkbox" name="camp_<?php echo $c_id; ?>[]" value="<?php echo $user_id; ?>" <?php if ($camp_id == $c_id and $camp_user_id == $user_id) echo 'checked="checked"'; ?> /><br />
<?php echo "camp_id = $camp_id <br /> c_id = $c_id <br /> camp_user_id = $camp_user_id <br /> user_id = $user_id"; ?></td>
<?php
}
?>
</tr>
<?php
}
?>
</table>
</form>
</div>
The results should come back in an array for each campaign like $_POST['camp_<id>'] where <id> is the campaign ID and the values in the array will be the users ID's.
Bookmarks