Jump to content


Photo

Need help with...


  • Please log in to reply
8 replies to this topic

#1 x8668k

x8668k
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 04 June 2006 - 09:41 PM

Hi, I'm new at php and have a little problem...

The code below works as I want it:

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

But I don't want a submit button, I want a link like:

<a href="Test1">Test1</a>

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\" /]

#2 calcop

calcop
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 05 June 2006 - 12:22 AM

Why even use a form? You don't have any input objects within your form.

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 05 June 2006 - 04:05 AM

you would do like this:
echo "<a href='".$_SERVER['PHP_SELF']."?test1=test1'>test1</a>";
echo "<a href='".$_SERVER['PHP_SELF']."?test2=test2'>test2</a>";

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:

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;
}
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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#4 x8668k

x8668k
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 05 June 2006 - 07:19 AM

[!--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) View Post[/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...

#5 x8668k

x8668k
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 05 June 2006 - 11:39 AM

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.

#6 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 05 June 2006 - 11:56 AM

This will do what you wanted ...

Providing you with multiple "pages" within one document.

<?php

echo "<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 "; }
?>
wisewood: proven fact, I am both wise, and wooden.

#7 x8668k

x8668k
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 05 June 2006 - 12:31 PM

[!--quoteo(post=380170:date=Jun 5 2006, 01:56 PM:name=wisewood)--][div class=\'quotetop\']QUOTE(wisewood @ Jun 5 2006, 01:56 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
This will do what you wanted ...

Providing you with multiple "pages" within one document.

<?php

echo "<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.

#8 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 05 June 2006 - 06:30 PM

well if you had even bothered to read my post...
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#9 x8668k

x8668k
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 06 June 2006 - 07:09 AM

[!--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) View Post[/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... :-/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users