x8668k Posted June 4, 2006 Share Posted June 4, 2006 Hi, I'm new at php and have a little problem...The code below works as I want it:[code]<html><body><? if (isset($Test2)) { echo "Test2"; } else if (isset($Test3)) { echo "Test3"; } else if (isset($Test4)) { echo "Test4"; } else if (isset($Test5)) { echo "Test5"; } else { echo "Test1"; }?><form action="<?php_self?>" method="post"> <input type="submit" name="Test1" value="Test1"> <input type="submit" name="Test2" value="Test2"> <input type="submit" name="Test3" value="Test3"> <input type="submit" name="Test4" value="Test4"> <input type="submit" name="Test5" value="Test5"></form></body></html>[/code]But I don't want a submit button, I want a link like:[code]<a href="Test1">Test1</a>[/code]Is that possible in some way?Thanks. [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/11191-need-help-with/ Share on other sites More sharing options...
calcop Posted June 5, 2006 Share Posted June 5, 2006 Why even use a form? You don't have any input objects within your form. Quote Link to comment https://forums.phpfreaks.com/topic/11191-need-help-with/#findComment-41907 Share on other sites More sharing options...
.josh Posted June 5, 2006 Share Posted June 5, 2006 you would do like this:[code]echo "<a href='".$_SERVER['PHP_SELF']."?test1=test1'>test1</a>";echo "<a href='".$_SERVER['PHP_SELF']."?test2=test2'>test2</a>";[/code]but a more efficient way to do it would be to have one variable: test and then to do conditions based off the value of that one variable. for example:[code]if (!$_GET['test']) { for ($x=1;$x<6;$x++;) { echo "<a href='".$_SERVER['PHP_SELF']."?test=".$x."'>".$x."</a><br>"; }} else { switch ($_GET['test']) { case 1,3,5: $type='odd'; break; case 2,4: $type='even'; break; default: $type='you didn't click on a link!'; break; }echo "test is: ".$type;}[/code]what that does is check to see if $_GET['test'] exists (that is, if you clicked on the link that would be blah.php?test=1 for instance). if it does not exist, then it prints 5 links. if you click on one of them, it will reload the page, except this time there will be a test variable being passed via the GET method, so it skips printing the links and goes to the ELSE. in the ELSE, here is an example of a condition based on the value. The switch statement assigns 'odd' to $type if the number is odd, 'even' if it is even, and by default, it assigns 'you didn't click on a link!' cuz there is always a possibility it is not 1-5 (like, if the user were to enter directly into the address bar blah.php?test=120 for instance). then it echos the results. Quote Link to comment https://forums.phpfreaks.com/topic/11191-need-help-with/#findComment-41941 Share on other sites More sharing options...
x8668k Posted June 5, 2006 Author Share Posted June 5, 2006 [!--quoteo(post=380082:date=Jun 5 2006, 02:22 AM:name=Matt D)--][div class=\'quotetop\']QUOTE(Matt D @ Jun 5 2006, 02:22 AM) [snapback]380082[/snapback][/div][div class=\'quotemain\'][!--quotec--]Why even use a form? You don't have any input objects within your form.[/quote]I'm trying to make a site that goes to Test1 the first time you got to it.The other Test2-5 can be, About, Contact, Gallery, Blog and what ever.The reason for this is that I wanna test if it is possible to have one index.php and thats all, no other files, everything shold be in that file.So this small file I have made that echos different categories is just a test, the final page will of course show more then just echo Test1... Quote Link to comment https://forums.phpfreaks.com/topic/11191-need-help-with/#findComment-41967 Share on other sites More sharing options...
x8668k Posted June 5, 2006 Author Share Posted June 5, 2006 This is what I want:[a href=\"http://x8668k.com/test.php\" target=\"_blank\"]http://x8668k.com/test.php[/a]But I want a normal link, not a submit button.This is part of a larger page but I have cut out the code I have problem with to make it easier to see.Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/11191-need-help-with/#findComment-41988 Share on other sites More sharing options...
wisewood Posted June 5, 2006 Share Posted June 5, 2006 This will do what you wanted ...Providing you with multiple "pages" within one document.<?phpecho "<a href=$_SERVER[PHP_SELF]?page=blog>Blog</a><br>";echo "<a href=$_SERVER[PHP_SELF]?page=about>About</a><br>";echo "<a href=$_SERVER[PHP_SELF]?page=gallery>Gallery</a><br>";echo "<a href=$_SERVER[PHP_SELF]?page=contact>Contact</a><br>";echo "<br><br>";if($_GET[page]=="blog"){ echo " blog script goes here "; }if($_GET[page]=="about"){ echo " about script goes here "; }if($_GET[page]=="gallery"){ echo " gallery script goes here "; }if($_GET[page]=="contact"){ echo " contact script goes here "; }?> Quote Link to comment https://forums.phpfreaks.com/topic/11191-need-help-with/#findComment-41989 Share on other sites More sharing options...
x8668k Posted June 5, 2006 Author Share Posted June 5, 2006 [!--quoteo(post=380170:date=Jun 5 2006, 01:56 PM:name=wisewood)--][div class=\'quotetop\']QUOTE(wisewood @ Jun 5 2006, 01:56 PM) [snapback]380170[/snapback][/div][div class=\'quotemain\'][!--quotec--]This will do what you wanted ...Providing you with multiple "pages" within one document.<?phpecho "<a href=$_SERVER[PHP_SELF]?page=blog>Blog</a><br>";echo "<a href=$_SERVER[PHP_SELF]?page=about>About</a><br>";echo "<a href=$_SERVER[PHP_SELF]?page=gallery>Gallery</a><br>";echo "<a href=$_SERVER[PHP_SELF]?page=contact>Contact</a><br>";echo "<br><br>";if($_GET[page]=="blog"){ echo " blog script goes here "; }if($_GET[page]=="about"){ echo " about script goes here "; }if($_GET[page]=="gallery"){ echo " gallery script goes here "; }if($_GET[page]=="contact"){ echo " contact script goes here "; }?>[/quote]Thank you wisewood that did it, nice to get help so quickly. [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]I changed it a little so it will go to the Blog page the first time you go to the page. Quote Link to comment https://forums.phpfreaks.com/topic/11191-need-help-with/#findComment-41997 Share on other sites More sharing options...
.josh Posted June 5, 2006 Share Posted June 5, 2006 well if you had even bothered to read my post... Quote Link to comment https://forums.phpfreaks.com/topic/11191-need-help-with/#findComment-42104 Share on other sites More sharing options...
x8668k Posted June 6, 2006 Author Share Posted June 6, 2006 [!--quoteo(post=380287:date=Jun 5 2006, 08:30 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ Jun 5 2006, 08:30 PM) [snapback]380287[/snapback][/div][div class=\'quotemain\'][!--quotec--]well if you had even bothered to read my post...[/quote]I did, but as I said, I'm new at this, I didn't get it to work... :-/ Quote Link to comment https://forums.phpfreaks.com/topic/11191-need-help-with/#findComment-42320 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.