vbcoach Posted June 4, 2014 Share Posted June 4, 2014 Hello. I have a sports league and the captain's page has a menu bar allowing links to sub pages. I would like to only add the URL part if a condition is met. In my database I have a league field called "session" for Spring or Summer sessions. The menu bar has 5 simple columns for hyperlinks: Home | Edit Team | Add Player | Edit My Information | Log Out | What I would like to do is to only display say the "Edit Team" with hyperlink if the league session = "Summer" (that was Spring teams cannot edit their information at this point in time). I am trying to create an IF-Else statement, but can't quite get it right. I am a novice PHP coder, so I could really use some help. Here is the current code for this short section: <table width="800" border="0" cellpadding="0" cellspacing="0"> <tr> <td><img src="images/BBV_CP_top.jpg" width="800" height="200"></td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="6%" class="menu"><a href="home.php"> Home</a> </td> <td width="9%" class="menu">Edit Team </a></td> <td width="12%" class="menu">Add Player</td> <td width="63%" class="menu">Edit My Information</a> </td> <td width="10%" class="menu"><a href="logout.php">Log Out </a></td> </tr> </table> How can I create "Edit Team" to be a hyperlink ONLY IF the condition (league = Summer) is TRUE? $team is the query that returns the league results from the MSSQL query. Thanks in advance for your help. Quote Link to comment https://forums.phpfreaks.com/topic/288988-need-help-adding-conditional-url/ Share on other sites More sharing options...
mlukac89 Posted June 4, 2014 Share Posted June 4, 2014 <table width="800" border="0" cellpadding="0" cellspacing="0"> <tr> <td><img src="images/BBV_CP_top.jpg" width="800" height="200"></td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="6%" class="menu"><a href="home.php"> Home</a> </td> <?php if (something === true) { echo '<td width="9%" class="menu">Edit Team </a></td>'; } ?> <td width="12%" class="menu">Add Player</td> <td width="63%" class="menu">Edit My Information</a> </td> <td width="10%" class="menu"><a href="logout.php">Log Out </a></td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/288988-need-help-adding-conditional-url/#findComment-1481899 Share on other sites More sharing options...
mogosselin Posted June 5, 2014 Share Posted June 5, 2014 The code you posted doesn't contain any PHP, it's only HTML. It would be easier to help you if you show us the part of your PHP code that makes the query (with your $team variable). What do you have so far? Quote Link to comment https://forums.phpfreaks.com/topic/288988-need-help-adding-conditional-url/#findComment-1481909 Share on other sites More sharing options...
vbcoach Posted June 5, 2014 Author Share Posted June 5, 2014 <?php require_once('access.php'); $info = $_SESSION; //This is for testing purposes only - outputs all variable name and values // $vars = get_defined_vars(); // print_r($vars); require_once('../database.php'); $query = "SELECT * FROM player WHERE team = $info[tid]"; $players = mssqlquery($query); /*if(mssqlrowsaffectedX(players) != 1) { mssqlclose(); header('Location: http://www.<xxx>.com'); } */ $t_query = "SELECT t.*, l.* FROM team as t, league as l WHERE t.league = l.l_id AND t.t_id = $info[tid]"; $t_info = mssqlquery($t_query); $team = mssqlfetchassoc($t_info); //mssqlclose(); move to end //print_r($team); //die(); //-------------------- ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title><xxx></title> <link rel="stylesheet" href="../cp/cpanel.css" type="text/css"> <script type="text/javascript" src="http://www.myipblocker.com/MyIpBlocker?code=LcaBENjdb21jL5MCWFo77w"></script> <script language="JavaScript" type="text/JavaScript"> <!-- function MM_reloadPage(init) { //reloads the window if Nav4 resized if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) { document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }} else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload(); } MM_reloadPage(true); //--> </script> <style type="text/css"> <!-- .style2 {color: #666666} --> </style> </head> <body> <table width="800" border="0" cellpadding="0" cellspacing="0"> <tr> <td><img src="images/BBV_CP_top.jpg" width="800" height="200"></td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="6%" class="menu"><a href="home.php"> Home</a> </td> <td width="9%" class="menu">Edit Team </a></td> <td width="12%" class="menu">Add Player</td> <td width="63%" class="menu">Edit My Information</a> </td> <td width="10%" class="menu"><a href="logout.php">Log Out </a></td> </tr> </table></td> </tr> <tr> <td><table width="765" border="0" cellspacing="1" cellpadding="1"> <?php if($info['feepaid'] == 'n') { ?> <tr> <td colspan="2" align="left" valign="top"> </td> </tr> <?php }?> <tr> <td width="37%" align="left" valign="top"><br> <table width="100%" border="0" cellpadding="2" cellspacing="0" class="grey2px"> <tr> <td colspan="2" class="dk_greyTxt"><h3><strong>Captain's Information</strong></h3></td> </tr> <tr> <td width="27%" class="dk_greyTxt"><strong>Name</strong></td> <td width="73%"><?php echo $info['cptname']; ?> </td> </tr> <tr> <td class="dk_greyTxt"><strong>Address</strong></td> <td><?php echo $info['address']; ?><br> <?php echo "$info[city], $info[state] $info[zip]"; ?> </td> </tr> <tr> <td class="dk_greyTxt"><strong>Phone</strong></td> <td><?php echo $info['phone'] ?></td> </tr> <tr> <td class="dk_greyTxt"><strong>E-mail</strong></td> <td><?php echo $info['email'] ?></td> </tr> <tr> <td class="dk_greyTxt"><strong>Shirt Size </strong></td> <td><?php echo $info['size'] ?></td> </tr> </table> <br></td> <td width="63%" rowspan="2" align="left" valign="top"><br> <table width="100%" cellpadding="1" cellspacing="0" class="grey2px"> <tr class="dk_greyTxt"> <td colspan="6"><h3><strong>Player's Information</strong></h3></td> </tr> <tr class="dk_greyTxt"> <td width="21%"><strong>Name</strong></td> <td width="23%"><strong>E-mail</strong></td> <td width="21%"><div align="center"><strong>Shirt Size</strong></div></td> <td width="19%"> </td> <td width="16%"> </td> </tr> <?php $i=0; while($row = mssqlfetchassoc($players)) { ?> <tr <?php if($i%2 == 0) echo "class='altbg'";?> > <td><?php echo $row['name'] ?></td> <td><?php echo $row['email'] ?></td> <td align="center"><?php echo $row['pshirt'] ?></td> <td><form name="del_player<?= $row['p_id'] ?>" action="remPlayer.php" method="post" onSubmit="return(confirm('Are you sure you want to delete <?= $row['name']?>?\n\nThis cannot be reversed'))"> </form></td> <td><form name="player<?= $row['p_id'] ?>" action="editPlayer.php" method="post"> </form></td> </tr> <?php $i++; } ?> </table></td> </tr> <tr> <td align="left" valign="top"><br> <table width="100%" border="0" cellpadding="2" cellspacing="0" class="grey2px"> <tr> <td colspan="2" class="dk_greyTxt"><h3>Team Information </h3></td> </tr> <tr> <td width="27%" class="dk_greyTxt"><strong>Name</strong></td> <td width="73%"><?php echo $team['teamname']; ?></td> </tr> <tr> <td class="dk_greyTxt"><strong>League</strong></td> <td><?php echo "$team[night] $team[type] $team[size]s"; ?></td> </tr> <tr> <td class="dk_greyTxt"><strong>Division</strong></td> <td><?php echo $team['division'] ?></td> </tr> <tr> <td class="dk_greyTxt"><strong>Shirt Color </strong></td> <td><?php echo $team['shirtcolor'] ?></td> </tr> <tr> <td class="dk_greyTxt"><strong>Registration Date </strong></td> <td><?php echo $team['reg_start'] ?></td> </tr> <?php if($info['feepaid'] == 'n') { ?> <?php } else { ?> <tr> <td class="dk_greyTxt"><strong>Registration Completed </strong></td> <td><?php echo $team['reg_done'] ?></td> </tr> <?php } ?> <?php mssqlclose(); ?> <tr> <td class="dk_greyTxt"><strong>Record </strong></td> <td> </td> </tr> </table></td> </tr> </table></td> </tr> </table> <br> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/288988-need-help-adding-conditional-url/#findComment-1481941 Share on other sites More sharing options...
cyberRobot Posted June 5, 2014 Share Posted June 5, 2014 What I would like to do is to only display say the "Edit Team" with hyperlink if the league session = "Summer" (that was Spring teams cannot edit their information at this point in time). I am trying to create an IF-Else statement, but can't quite get it right. Could you show the code you tried? Quote Link to comment https://forums.phpfreaks.com/topic/288988-need-help-adding-conditional-url/#findComment-1481949 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.