slapdashgrim Posted July 16, 2007 Share Posted July 16, 2007 Hello i am writing a code to display a link with php becuase the link has to go to a page that is named with a variable but i cant get the variable to print! i have tried many things. here it is <?php $m = "Grimslapdash"; if(isset($m)){ } else { print "<A href=\"$m.php\">$m</a>"; } ?> i want it to print the link only if the variable is set. and the link will be <a href="$m.php">$m</a> or <a href="Grimslapdash.php">Grimslapdash</a> all it does now is print <a href=".php"></a> the variable $m is not printing Quote Link to comment Share on other sites More sharing options...
paul2463 Posted July 16, 2007 Share Posted July 16, 2007 <?php $m = "Grimslapdash"; if(isset($m)){ } else { print "<A href=\"$m.php\">$m</a>"; } ?> for a start it should show nothing because your code asks if $m is set then do nothing else create the link try this one <?php $m = "Grimslapdash"; if(!isset($m)){ } else { print "<A href=\"$m.php\">$m</a>"; } ?> works on my system Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 16, 2007 Share Posted July 16, 2007 echo "<a href='".$m."'.php>".$m."</a>"; Quote Link to comment Share on other sites More sharing options...
hcdarkmage Posted July 16, 2007 Share Posted July 16, 2007 Try <?php $m = "Grimslapdash"; if(isset($m)){ } else { print "<a href="'.$m.'.php">$m</a>"; } ?> EDIT:Darn. A little late on the send button. Quote Link to comment Share on other sites More sharing options...
slapdashgrim Posted July 16, 2007 Author Share Posted July 16, 2007 okay that will work hopfully but could some one explain what i did wrong THANKYOU FOR THE HELP Quote Link to comment Share on other sites More sharing options...
paul2463 Posted July 16, 2007 Share Posted July 16, 2007 if you look at my offering you will see what happened if you set a variable with a value and then check to see whether it is set using isset() it will either be true or false depending ( in this case TRUE because you set it with slapdashgrim) in your code you checked to see whether it was set if(isset($m)) { } which says if the variable IS SET then do nothing because there is no associated code between the curly braces your code goes on to else { print "<a href="'.$m.'.php">$m</a>"; } to say if it didnt exist create this link with the variable that does not exist ergo <a href=".php"></a> what you needed was the negater "!" in there to say if it DOES NOT exist do nothing ELSE create the link so the final code should be <?php $m = "Grimslapdash"; if(!isset($m)){ } else { print "<A href=\"$m.php\">$m</a>"; } ?> hope that helps Quote Link to comment Share on other sites More sharing options...
slapdashgrim Posted July 16, 2007 Author Share Posted July 16, 2007 thankyou works great now! 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.