Jump to content

IF statement help


martin9t9

Recommended Posts

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!

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
?>  

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.