timmah1 Posted December 17, 2007 Share Posted December 17, 2007 Why do these links show up twice? $data = array( 'seller' => array(' <p><a href="member.php">My Account</a></p> <p><a href="main.php?cid=list">List Items</a></p> <p><a href="main.php?cid=myitems">My Items</a></p> <p><a href="member.php?change=password">Change Password</a></p> <p><a href="member.php?change=email">Change Email</a></p> <p><a href="main.php?cid=logout">Logout</a></p> <p></p> <p><a href="member.php?change=account">Close account</a></p>'), 'buyer' => array(' <p><a href="member.php">My Account</a></p> <p><a href="member.php?change=password">Change Password</a></p> <p><a href="member.php?change=email">Change Email</a></p> <p><a href="main.php?cid=logout">Logout</a></p> <p></p> <p><a href="member.php?change=account">Close account</a></p>'), //buyer => array(<p><a href="member.php?change=password">Buyer</a></p>'), '<p>Welcome to the members only page '.$_SESSION['s_name'].'!</p> <p>You are logged in as '.$_SESSION['s_username'].' from the IP address '.$_SERVER['REMOTE_ADDR'].'</p>', ); $type = $_SESSION['s_type']; foreach($data[$type] as $val) { echo $val; } This is what shows up Main Links close - Navigation My Account Change Password Change Email Logout Close account Welcome to the members only page! You are logged in as cheezy from the IP address xx.xxx.xx.xxx close - Login information My Account Change Password Change Email Logout Close account Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 17, 2007 Share Posted December 17, 2007 I am not sure. You are echoing $val which is set to the value of $data which stores two arrys of information. Therefore both bit of information are being echoed. Quote Link to comment Share on other sites More sharing options...
timmah1 Posted December 17, 2007 Author Share Posted December 17, 2007 I'm not sure either, that's why I'm posting it here to see if I coded it wrong. Here is the entire code if that helps <?php session_start(); if($_GET['set'] > 0) { if($_SESSION['whattoclose'] == NULL) { $_SESSION['whattoclose'] = $_GET['set']; } else { $_SESSION['whattoclose'] = $_SESSION['whattoclose'] . '|' . $_GET['set']; } } if($_GET['undo'] > 0) { if(!empty($_SESSION['whattoclose'])){ $_SESSION['whattoclose'] = str_replace("|".$_GET['undo'] , "" , $_SESSION['whattoclose']); $_SESSION['whattoclose'] = str_replace($_GET['undo'] , "" , $_SESSION['whattoclose']); } } function showTitle($id) { $title = array( "Navigation", "Login information", ); $data = $_SESSION['whattoclose']; $not = explode( "|" , $data ); if(!in_array( $id , $not )) { echo '<a href="member.php?set='.$id.'">close</a> - '; echo $title[$id-1]; } else { echo '<a href="member.php?undo='.$id.'">open</a> - '; echo $title[$id-1]; } } function checkIt($id) { $data = array( 'seller' => array(' <p><a href="member.php">My Account</a></p> <p><a href="member.php?change=list">List Items</a></p> <p><a href="member.php?change=myitems">My Items</a></p> <p><a href="member.php?change=password">Change Password</a></p> <p><a href="member.php?change=email">Change Email</a></p> <p><a href="main.php?cid=logout">Logout</a></p> <p></p> <p><a href="member.php?change=account">Close account</a></p>'), 'buyer' => array(' <p><a href="member.php">My Account</a></p> <p><a href="member.php?change=password">Change Password</a></p> <p><a href="member.php?change=email">Change Email</a></p> <p><a href="main.php?cid=logout">Logout</a></p> <p></p> <p><a href="member.php?change=account">Close account</a></p>'), //buyer => array(<p><a href="member.php?change=password">Buyer</a></p>'), '<p>Welcome to the members only page '.$_SESSION['s_name'].'!</p> <p>You are logged in as '.$_SESSION['s_username'].' from the IP address '.$_SERVER['REMOTE_ADDR'].'</p>', ); $type = $_SESSION['s_type']; foreach($data[$type] as $val) { echo $val; } $str = $_SESSION['whattoclose']; $not = explode( "|" , $str ); if(!in_array( $id , $not )) { echo '<div class="table">'; echo $data[$id-1]; echo '</div>'; } } ?> <div class="header"> <? showTitle(1) ?> </div> <? checkIt(1) ?> <br> <div class="header"> <? showTitle(2) ?> </div> <? checkIt(2) ?> Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 17, 2007 Share Posted December 17, 2007 It is because you are calling on the function and echoing $val. Therefore you are asking it to print twice. Quote Link to comment Share on other sites More sharing options...
timmah1 Posted December 17, 2007 Author Share Posted December 17, 2007 So I should pull this out? function checkIt($id) Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 17, 2007 Share Posted December 17, 2007 yeah i think so. Give it a try and see what happens. Quote Link to comment Share on other sites More sharing options...
timmah1 Posted December 17, 2007 Author Share Posted December 17, 2007 Now I keep getting errors I'm going to play with it and see why, if I can't get it fixed, I'll be back :-) Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 17, 2007 Share Posted December 17, 2007 you have to remove that and ''function checkIt($id)'' and just start with $data. Quote Link to comment Share on other sites More sharing options...
timmah1 Posted December 17, 2007 Author Share Posted December 17, 2007 When I pull this out function checkIt($id) { I get an error on line 99, which is this echo '</div>'; This is the revised code //function checkIt($id) //{ $data = array( 'seller' => array(' <p><a href="member.php">My Account</a></p> <p><a href="member.php?change=s-guide">Sellers Guide FAQ</a></p> <p><a href="member.php?change=list">List Items</a></p> <p><a href="member.php?change=myitems">My Items</a></p> <p><a href="member.php?change=password">Change Password</a></p> <p><a href="member.php?change=email">Change Email</a></p> <p><a href="main.php?cid=logout">Logout</a></p> <p></p> <p><a href="member.php?change=account">Close account</a></p>'), 'buyer' => array(' <p><a href="member.php">My Account</a></p> <p><a href="member.php?change=password">Change Password</a></p> <p><a href="member.php?change=email">Change Email</a></p> <p><a href="main.php?cid=logout">Logout</a></p> <p></p> <p><a href="member.php?change=account">Close account</a></p>'), //buyer => array(<p><a href="member.php?change=password">Buyer</a></p>'), '<p>Welcome to the members only page '.$_SESSION['s_name'].'!</p> <p>You are logged in as '.$_SESSION['s_username'].' from the IP address '.$_SERVER['REMOTE_ADDR'].'</p>', ); $type = $_SESSION['s_type']; foreach($data[$type] as $val) { echo $val; } $str = $_SESSION['whattoclose']; $not = explode( "|" , $str ); if(!in_array( $id , $not )) { echo '<div class="table">'; echo $data[$id-1]; echo '</div>'; } } ?> <div class="header"> <? showTitle(1) ?> </div> <? checkIt(1) ?> <br> <div class="header"> <? showTitle(2) ?> </div> <? checkIt(2) ?> Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 17, 2007 Share Posted December 17, 2007 try this. I have removed the function and the div. Get the simple part working then we can add more. <?php session_start(); if($_GET['set'] > 0) { if($_SESSION['whattoclose'] == NULL) { $_SESSION['whattoclose'] = $_GET['set']; } else { $_SESSION['whattoclose'] = $_SESSION['whattoclose'] . '|' . $_GET['set']; } } if($_GET['undo'] > 0) { if(!empty($_SESSION['whattoclose'])){ $_SESSION['whattoclose'] = str_replace("|".$_GET['undo'] , "" , $_SESSION['whattoclose']); $_SESSION['whattoclose'] = str_replace($_GET['undo'] , "" , $_SESSION['whattoclose']); } } function showTitle($id) { $title = array( "Navigation", "Login information", ); $data = $_SESSION['whattoclose']; $not = explode( "|" , $data ); if(!in_array( $id , $not )) { echo '<a href="member.php?set='.$id.'">close</a> - '; echo $title[$id-1]; } else { echo '<a href="member.php?undo='.$id.'">open</a> - '; echo $title[$id-1]; } } $data = array( 'seller' => array(' <p><a href="member.php">My Account</a></p> <p><a href="member.php?change=list">List Items</a></p> <p><a href="member.php?change=myitems">My Items</a></p> <p><a href="member.php?change=password">Change Password</a></p> <p><a href="member.php?change=email">Change Email</a></p> <p><a href="main.php?cid=logout">Logout</a></p> <p></p> <p><a href="member.php?change=account">Close account</a></p>'), 'buyer' => array(' <p><a href="member.php">My Account</a></p> <p><a href="member.php?change=password">Change Password</a></p> <p><a href="member.php?change=email">Change Email</a></p> <p><a href="main.php?cid=logout">Logout</a></p> <p></p> <p><a href="member.php?change=account">Close account</a></p>'), //buyer => array(<p><a href="member.php?change=password">Buyer</a></p>'), '<p>Welcome to the members only page '.$_SESSION['s_name'].'!</p> <p>You are logged in as '.$_SESSION['s_username'].' from the IP address '.$_SERVER['REMOTE_ADDR'].'</p>', } $type = $_SESSION['s_type']; foreach($data[$type] as $val) { echo $val; $str = $_SESSION['whattoclose']; $not = explode( "|" , $str ); if(!in_array( $id , $not )) { echo '<div class="table">'; echo $data[$id-1]; echo '</div>'; } } ?> Quote Link to comment Share on other sites More sharing options...
timmah1 Posted December 17, 2007 Author Share Posted December 17, 2007 I tried that and got errors, so I tried to remove <div class="header"> <? showTitle(1) ?> </div> <? ?> <br> <div class="header"> <? showTitle(2) ?> </div> <? checkIt(2) ?> And everything works! I guess I don't need to have them have the ability to open and close the information, just thought it would be different. Thanks for all of your help adam, it's really appreciated Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 17, 2007 Share Posted December 17, 2007 As you are echoing the information it will be echoed no matter if the code calls on a fuction or not. Quote Link to comment 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.