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 Link to comment https://forums.phpfreaks.com/topic/60288-solved-the-print-function-help/ 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 Link to comment https://forums.phpfreaks.com/topic/60288-solved-the-print-function-help/#findComment-299878 Share on other sites More sharing options...
teng84 Posted July 16, 2007 Share Posted July 16, 2007 echo "<a href='".$m."'.php>".$m."</a>"; Link to comment https://forums.phpfreaks.com/topic/60288-solved-the-print-function-help/#findComment-299879 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. Link to comment https://forums.phpfreaks.com/topic/60288-solved-the-print-function-help/#findComment-299880 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 Link to comment https://forums.phpfreaks.com/topic/60288-solved-the-print-function-help/#findComment-299882 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 Link to comment https://forums.phpfreaks.com/topic/60288-solved-the-print-function-help/#findComment-299889 Share on other sites More sharing options...
slapdashgrim Posted July 16, 2007 Author Share Posted July 16, 2007 thankyou works great now! Link to comment https://forums.phpfreaks.com/topic/60288-solved-the-print-function-help/#findComment-299904 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.