I'm noob in php, and i'm trying to concatenate href with words or values ex:
$name = "anonymous";
echo ''.$name.'<br/>';
I want it to look like this when the user clicked the link.
echo ''.$name.'<br/>';
I've tried doing this, but it's not working.
echo ''.$name.'<br/>';
echo ''.$name.'<br/>';
The same way you concatenated the text.
You cant use php tags inside a php tag like this,
echo ''.$name.'<br/>';
It will mess the PHP interpreter so use this
echo "<a href=profile.php/{$name}>".$name."</a><br/>";
Related
I am trying to create a link within a text, I have 2 columns in my table (updates1) and (link1) updates 1 contains a text while link 1 contains a link. The problem is whenever im trying to call it the data or the link itself is being an output besides the text. I need it to be stored inside the text.
echo "<b><h4>{$list["updates1"]}<a>{$list["link1"]}</a></b></h4><hr>";
Try this:
echo '<b><h4>'.$list["updates1"].'</h4></b><hr>';
As per OP's example in the comment:
echo '<b><h4>'.$list["updates1"].'</b></h4><hr>';
Close the <h4> tag before the <b> tag, like this:
echo "<b><h4>{$list["updates1"]}<a>{$list["link1"]}</a></h4></b><hr>";
echo "<b><h4>{$list['updates1']} Your Link Title</h4></b><hr>";
EDIT: Try to close proper way tag
in php you can go through
echo "<b><h4><a href='".$list["link1"]."'>".$list['updates1']."</a></b></h4><hr>";
you can also try it using "\"
echo "<b><h4> {$list['updates1']}</h4></b><hr>";
I am struggling with an issue which I need a little bit of help with, basically I have created a search bar and when the results come up I only want the 'Session 1' or 'Session 2' to be href'd. Not the whole thing. A photo below:
img http://gyazo.com/eb677171c15b075f1fb4137d28227b3a.png
I would just like the Sessions to be hrefed but the paragraphs just.
My code below:
echo "<p><a href='../pages/session.php</a>".$results['1']."'><h3>".$results['title']."</h3>".$results['text']."</p>";
Linking to my DB
Note that is not all of my code just where I believe the issue lies.
You placed </a> slightly wrong. The correct solution would be like this:
echo "<p><a href='../pages/session.php'>{$results['1']}</a><h3>{$results['title']}</h3>{$results['text']}</p>";
If you use double quotes, you do not need to concatenate variables into your string, they are also validate within the string.
UPDATE
To display only the headlines as links try this:
echo "<a href='../pages/session.php'><h3>{$results['title']}</h3></a><p>{$results['text']}</p>";
You have missed a bracket in ur a tag.It is like <a href='whatever'>blah</a>
Do you just want to href $results['1']? Here you go.
echo "<p><a href='../pages/session.php'>".$results['1']."</a><h3>".$results['title']."</h3>".$results['text']."</p>";
I have a problem I can't solve by myself, don't know how simple it is to solve but I want to open this link in another frame:
<?php echo "<a href=details.php?id=$row[idProdukt]>$row[Produkt_Namn]</a>" ?>
tried to use taget but since it's html I couldn't really wrap my head around how to type it.
any help is greatly appreciated.
Just add the attribute to your anchor tag as usual. Make sure you use the name of the targeted iframe as its value:
<?php echo "<a href='details.php?id=$row[idProdukt]' target='framename'>$row[Produkt_Namn]</a>" ?>
I added quotes around your html attribute values as that is a good practice to be in. It prevents issues arising from errant or intentional spaces in attribute values.
First, you have error on array index, missing quotes. You can use this;
<iframe src="some_url" name="test">
.....
</iframe>
<?php echo "" . $row['Produkt_Namn'] . ""; ?>
The trouble is missing quotes around href attribute value and array key.
echo "{$row['Produkt_Namn']}";
See in action
I'm using a while statement on this and I can echo each row fine i.e
echo $row['myrow'];
but what I want is to have the result put into a link like so:
echo "<img src='http://www.mysite.com/images/$row['myrow'].jpg'>";
But it doesn't work. What am I doing wrong?
Either echo it this way:
echo "<img src='http://www.mysite.com/images/{$row['myrow']}.jpg'>";
Or, IMHO much better, this way:
echo "<img src='http://www.mysite.com/images/".$row['myrow'].".jpg'>";
Give the documentation on double quoted-strings a quick refresh.
Another nice way to do it is to only use PHP for the dynamic part of the code. I think it results in nicer looking code.
<img src="http://www.mysite.com/images/<?php echo $row['myrow']; ?>.jpg">
Then of course the whole img tag should not be in a PHP code block, since it regular HTML.
You need to take care of your quotes...
Try this:
echo '<img src="http://www.mysite.com/images/'.$row['myrow'].'.jpg" />';
Also notice that you didn't close the element.
Accessing array elements and object properties/methods inside the string must be enclosed in curly braces (string parsing)
echo "<img src='http://www.mysite.com/images/{$row['myrow']}.jpg'>";
to make it complete, lol
echo "<img src='http://www.mysite.com/images/$row[myrow].jpg'>";
you have write your site url on place of example.com
echo "<img src='example.com/images/'.$row['myrow'].'.jpg'>";
I found this tutorial that explains what I want to do using html but when I echo out the code with a get variable there is no affect to the page. I would use, for example, the following code:
echo "<a href='post.php?id=".$id."#Comments'>Click here to go to the comments</a>";
echo "<a title='Comments'>Comments</a>";
I presume the problem is to do with the get variable, so would I have to end it, some how, before using the # symbol?
The problem actually lies in your HTML, because the anchor should be parsed correctly by browsers regardless of the query string.
Page anchors use the name attribute instead of the title attribute:
<a name='Comments'>Comments</a>
You can also apply this to the id attribute of any element:
<h2 id='Comments'>Comments</h2>
To define jump-labels you have to set a name and/or id-attribute:
echo "<a title='Comments' name='Comments' id='Comments'>Comments</a>";