I need a little help pulling some info from a MySQL DB. I have 3 tables, accounts, subscriptionItems, & subscriptionList
accounts contain user information and accountID
These are the tables in my DB
subscriptionItems
subscriptionID
name
status
subscriptionList
subscriptionListID
accountID
subscriptionID
subscriptionItems hold the names of the things people can subscribe to. subscriptionList holds the actual list of subscribers. What I want to do is list all the names of items, then to the right of them, list the amount of subscribers. What I have kindof works, but not correctly. Below is what I am using.
Here is the output:
------Subscriptions---------------------------------Options-------------------Amount
Construction/Road Closures------------------ Edit - Delete-----------------------1
Pool Updates-------------------------------------Edit - Delete-----------------------2
Recreation Updates-----------------------------Edit - Delete-----------------------2
Senior Center------------------------------------Edit - Delete-----------------------2
in Pool Updates, Recreation Updates, and Senior Center there are 0 subscribers, so the result should be zero. I'm sure what is happening is when it is just sticking with the last $amount variable given... but I'm not sure how to fix it.
I tried joins, but they didn't seem to be working, at at this point, they seem a tad over my head.
Thanks for any help!
accounts contain user information and accountID
These are the tables in my DB
subscriptionItems
subscriptionID
name
status
subscriptionList
subscriptionListID
accountID
subscriptionID
subscriptionItems hold the names of the things people can subscribe to. subscriptionList holds the actual list of subscribers. What I want to do is list all the names of items, then to the right of them, list the amount of subscribers. What I have kindof works, but not correctly. Below is what I am using.
<table width="450" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="210" align="center"><strong>Subscription Name </strong></td>
<td width="175" align="center"><strong>Options</strong></td>
<td width="65" align="center"><strong>Amount</strong></td>
</tr>
<?
$result = mysql_query("SELECT * FROM subscriptionItems ORDER BY name ASC",$connect);
while($row = mysql_fetch_assoc($result)){
$subscriptionID = $row['subscriptionID'];
$name = $row['name'];
$color1="#FFFFFF";
$color2="#EEEEEE";
$bgcolor=($bgcolor==$color1)?$color2:$color1;
?>
<tr bgcolor="<?=$bgcolor;?>">
<td><?=$name?></td>
<td align="center">Edit - Delete </td>
<td align="center"><?
if(isset($subscriptionID)){
$result2 = mysql_query("SELECT * FROM subscriptionList WHERE subscriptionID='$subscriptionID' ",$connect);
while($row2 = mysql_fetch_assoc($result2))
$amount = mysql_num_rows($result2);
echo $amount;
}else{
echo $amount;
}
?></td>
</tr>
<?
}
?>
</table>
Here is the output:
------Subscriptions---------------------------------Options-------------------Amount
Construction/Road Closures------------------ Edit - Delete-----------------------1
Pool Updates-------------------------------------Edit - Delete-----------------------2
Recreation Updates-----------------------------Edit - Delete-----------------------2
Senior Center------------------------------------Edit - Delete-----------------------2
in Pool Updates, Recreation Updates, and Senior Center there are 0 subscribers, so the result should be zero. I'm sure what is happening is when it is just sticking with the last $amount variable given... but I'm not sure how to fix it.
I tried joins, but they didn't seem to be working, at at this point, they seem a tad over my head.
Thanks for any help!