Half way through writing this I realized that I'm pretty much just explaining Jacek's " User Profiles " tutorial to you. If you watch it I bet you'll get an idea of how to do this even better.
http://www.youtube.com/watch?v=SSpSczxobK8I would create a group page next.
I would do it like this:
Create a function which fetches all the data associated with the group.
[syntax=php]
<?php
function fetch_group_info($gid){
$gid = (int)$gid;
$sql = "SELECT `group_name`, `created_by` FROM `groups` WHERE `group_id` = {$gid}";
// Run query and return array.
}
?>[/syntax]
And another function which checks if the user is already subscribed or not.
[syntax=php]
<?php
function is_subscribed($gid, $member){
$gid = (int)$gid;
$member = mysql_real_escape_string($member); // I'm assuming member is a varchar string ( username ) and not the id.
// Run query and see if subscribed is equal to 1. If it is, return true, otherwise, return false.
$result = mysql_query("
SELECT `subscribed`
FROM
`group_members`
WHERE
`group_id` = '{$gid}'
AND
`member` = '{$member}'
");
$subscribed = mysql_result($result, 0);
return ($subscribed == 1 ? true : false);
}
?>[/syntax]
Create a new document and call it group_info.php ( name it whatever you want ).
This is where you're gonna display all the group info, so we call the first function.
See User Profile Tutorials on how to code this page. Just swap any user info with group info. Easy as that.
Next up is the is_subscribed function. Because you wanted to display a join group button if the user was not already a member.
This one is pretty simple.
[syntax=php]<?php
if(is_subscribed($gid,$member) == true){
// Show regular page
}else{
echo "<a href='join_group.php?gid=". {$gid} ."'>Join Group</a><br />";
}
?>[/syntax]
You can use what you learn from the User Profiles tutorial to code everything you need.