creating a hyperlink inside a table using php/mysql - php

I am trying to create a hyperlink using php. the hyper link is in a table..
this is my code:
echo"<tr><td>"click here</td></tr>";
I am getting an error
How can i fix this?

It should be
echo"<tr><td><a href='".$row['hyperPath'] . "'>click here</a></td></tr>";
You had an extra " after your tag. If you really want the " to be displayed you need to escape it first with \ like this:
echo"<tr><td>\"<a href='".$row['hyperPath'] . "'>click here</a></td></tr>";
You were also missing the closing quote for your href attribute (added before >click here)

try this
echo "<tr><td><a href='".$row['hyperPath']."'>click here</a></td></tr>";

Related

Link within a text in another column php

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

How do i fix this dynamic query parameter in PHP?

I'm trying to get a URL to have a dynamic parameter based on the value of a variable.
Here's what Im doing
echo "The file name is ".$value.''.$value.''."<br>";
However, when I click on the corresponding link I get the following URL in the browser
http://localhost/HelloWorld/filespecificpage.php?filename=<?php echo $value ?> rather than the actual value in $value. Any help on how I can fix this would be appreciated.
PHP Noob here, appreciate the patience.
You're already in PHP script mode, you don't need <?php. You just need to concatenate the variable, like you did earlier in the line. You should also use urlencode() when substituting a variable into a URL parameter.
echo "The file name is ".$value.''.$value.''."<br>";
If you break the PHP String/Echo dont use the doublequotes, it makes your live much harder as you need ist.
For your question
echo 'The file name is ' . $value . '<a href="filespecificpage.php?filename=' . urlencode($value) . '>' . $value . '</a><br>';
An expample why single and not doublequotes. If you write an Hyperlink in HTML you use
Link description
and all is fine.
If you do it in an PHP echo with doublequotes you must escape all quotes.
echo "Link description";
Perfect look and way
echo '<a href="website" target="_blank" ' . $anyPHPvar . '>Link description</a>';
and you can use " for clear html and ' for PHP ;)
So, use singlequotes makes your life easyer and its a little bit faster and welcome to PHP ;)

How to concatenate variable with anchor's href

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/>";

Target in Echoed php link

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

pop up from linkl

I have a link that I would like to open a page in a pop up, the link and onclick work fine but open it in a new full window but when I add the part after '_blank' it stops working. Here's my code
echo '<li>'.$img.''.$item_name.'</li>';
I suspect there is a typo or a problem with my syntax but I can't find it.
Any help would be appreciated
echo '<li>'.$img.''.$item_name.'</li>';
echo '<li>'.$img.'test'.$item_name.'</li>';
You are missing some closing single quotes in the window.open arguments, and the arguments you are passing are slightly incorrect. _blank is a separate argument from URL (the first argument,) URL needs a closing single quote, and NAME needs an opening single quote. corrected code is below
echo('<li>' . $img . '' . $item_name . '</li>');

Categories