martin9t9 Posted May 23, 2011 Share Posted May 23, 2011 hey guys, I'm making a website where you can join different groups and you can post comments in that group. ive got a few databases, one has all the groups in it and the other one has the comments in it and what group you commented in. then i have a page where you join the groups which just inserts all the group names from the database then theres a 'join' button... i need to know how to make that change from 'join' to 'unjoin' once its been clicked on by the user so they cant join the group heaps of times. im using two databases so im unsure how i would do this, ive experimented a bit but i cant work it out. Please Help! Quote Link to comment https://forums.phpfreaks.com/topic/237207-if-statement-help/ Share on other sites More sharing options...
KevinM1 Posted May 23, 2011 Share Posted May 23, 2011 Gonna need to see some code. Quote Link to comment https://forums.phpfreaks.com/topic/237207-if-statement-help/#findComment-1219026 Share on other sites More sharing options...
martin9t9 Posted May 23, 2011 Author Share Posted May 23, 2011 This is the code for the page that has the join buttons on it <?php require_once('auth.php'); ?> <?php $id = $_SESSION['SESS_MEMBER_ID'] ?> <html> <head> <title>Profile -</title> </head> <body> <table border="0" width="100%" height="100%"> <tr height="15%"> <td colspan="5"><?php include "header.php"; ?></td> </tr> <tr> <td> <table border="0" width="100%" height="100%"> <tr> <td width="25%" valign="top"><div valign="top"><?php include "menu.php"; ?></div></td> <td width="50%" valign="top"><center> <table width="100%" height="100%" border="1" cellspacing="0" cellpadding="0" bordercolor="black"> <tr> <td> <h2><center><b>Your Profile</b></center></h2> <?php include 'profile-menu.php'; ?><br /> <div class="subheading"><center><b>Join A Network</b></center></div> <p> <?php $host="***"; // Host name $username="martin9t9"; // Mysql username $password="***"; // Mysql password $db_name="martin9t9"; // Database name $tbl_name="networks"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ ?> <?php $network = $rows['network']; ?> <table border="0" width="100%"> <tr><div class="text"> <td class="postname"><? echo $rows['network']; ?><td> <td width="20%"> <a href="join-network-exec.php?network=<?php echo $network?>">Join</a> </td> </div></tr> </table> <hr color="#F0F0F0 "> <? } mysql_close(); //close database ?> <p/> </td> </tr> </table> </center></td> <td width="25%"></td> </tr> </table> </td> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/237207-if-statement-help/#findComment-1219027 Share on other sites More sharing options...
martin9t9 Posted May 23, 2011 Author Share Posted May 23, 2011 heres the code that adds the group to the database <?php require_once('auth.php'); ?> <?php $host="***"; // Host name $username="martin9t9"; // Mysql username $password="***"; // Mysql password $db_name="martin9t9"; // Database name $tbl_name="usernetworks"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); $id = $_SESSION['SESS_MEMBER_ID']; $first = $_SESSION['SESS_FIRST_NAME']; $last = $_SESSION['SESS_LAST_NAME']; $email = $_SESSION['SESS_USER']; $network = trim($_GET['network']); $sql="INSERT INTO $tbl_name (uid, first, last, email, network) VALUES('$id','$first','$last','$email','$network')"; $result=mysql_query($sql); //check if query successful if($result){ header("location: join-network.php"); } else { echo "ERROR"; } mysql_close(); ?> if youd like to see the final product go to http://martin9t9.com/announcement/ and register go to view profile then join a network. Quote Link to comment https://forums.phpfreaks.com/topic/237207-if-statement-help/#findComment-1219029 Share on other sites More sharing options...
PFMaBiSmAd Posted May 23, 2011 Share Posted May 23, 2011 Get a list of the network membership names for the current visitor as an array in some variable: $n_membership Then inside your while(){} loop, test if the current network name is in the $n_membership array and produce the appropriate link - $link = (in_array($network,$n_membership)) ? "produce un-join link here..." : "produce join link here..." ; Then simply echo the $link variable at the appropriate place in your code. Quote Link to comment https://forums.phpfreaks.com/topic/237207-if-statement-help/#findComment-1219039 Share on other sites More sharing options...
hemo-ali Posted May 23, 2011 Share Posted May 23, 2011 very nice codes thanks Quote Link to comment https://forums.phpfreaks.com/topic/237207-if-statement-help/#findComment-1219068 Share on other sites More sharing options...
martin9t9 Posted May 24, 2011 Author Share Posted May 24, 2011 PFMaBiSmAd i dont quite understand.... could you please place that piece of code into mine please, because i have tried and it doesnt work. thanks Quote Link to comment https://forums.phpfreaks.com/topic/237207-if-statement-help/#findComment-1219449 Share on other sites More sharing options...
PFMaBiSmAd Posted May 24, 2011 Share Posted May 24, 2011 If you post the code you tried, someone can probably help you with it. Quote Link to comment https://forums.phpfreaks.com/topic/237207-if-statement-help/#findComment-1219484 Share on other sites More sharing options...
martin9t9 Posted May 24, 2011 Author Share Posted May 24, 2011 this is the code i tried with the code you gave me <?php require_once('auth.php'); ?> <?php $id = $_SESSION['SESS_MEMBER_ID'] ?> <html> <head> <title>Profile - Announcement</title> </head> <body> <table border="0" width="100%" height="100%"> <tr height="15%"> <td colspan="5"><?php include "header.php"; ?></td> </tr> <tr> <td> <table border="0" width="100%" height="100%"> <tr> <td width="25%" valign="top"><div valign="top"><?php include "menu.php"; ?></div></td> <td width="50%" valign="top"><center> <table width="100%" height="100%" border="1" cellspacing="0" cellpadding="0" bordercolor="black"> <tr> <td> <h2><center><b>Your Profile</b></center></h2> <?php include 'profile-menu.php'; ?><br /> <div class="subheading"><center><b>Join A Network</b></center></div> <p> <?php $host="***"; // Host name $username="martin9t9"; // Mysql username $password="***"; // Mysql password $db_name="martin9t9"; // Database name $tbl_name="networks"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ $link = (in_array($network,$n_membership)) ? "produce un-join link here..." : "produce join link here..." ; ?> <?php $network = $rows['network']; ?> <table border="0" width="100%"> <tr><div class="text"> <td class="postname"><? echo $rows['network']; ?><td> <td width="20%"> <?php echo $link; ?> </td> </div></tr> </table> <hr color="#F0F0F0 "> <? } mysql_close(); //close database ?> <p/> </td> </tr> </table> </center></td> <td width="25%"></td> </tr> </table> </td> </tr> </table> </body> </html> <?php $host="***"; // Host name $username="martin9t9"; // Mysql username $password="***"; // Mysql password $db_name="martin9t9"; // Database name $tbl_name="usernetworks"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name WHERE uid='$id' ORDER BY id DESC"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ ?> <?php $n_membership = $rows['network']; ?> <? } mysql_close(); //close database ?> Quote Link to comment https://forums.phpfreaks.com/topic/237207-if-statement-help/#findComment-1219487 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.