Jump to content

[SOLVED] The Print() function help


slapdashgrim

Recommended Posts

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.