Using php/mysql to populate href link - php

I want my hyperlinks destination to be filled by a value from my database. However, when I click the link in my app it doesn't clear the "http://localhost/videoStorageApp/" before inserting the URl value from the database.
QUESTION: How do I clear the web browser url so only the URL value form the database is used?
WHAT I AM GETTING: http://localhost/videoStorageApp/'www.sonsofanarchy.tv'
WHAT I WANT: www.sonsofanarchy.tv
CODE:
This is the line that displays the hyperlink in question, if more code is needed please ask and ill add anything else that's needed:
echo '<td> ' . $row['url'] . '</td>';

echo '<td> ' . $row['url'] . '</td>';

You are probably missing "http://" in your href attribute.
<a href="google.com">
... will take you to http://currentsite.com/maybe-a-subfolder/google.com
<a href="http://google.com">
... will take you to http://google.com

Related

How can I turn this row into a link?

I want to make that row a link, but I dont know how to add an a href attribute... That row shows information from a DB and I just want to make ir clickeable and not only as plain text. Thank you
This is the row I wanna turn into a link...
echo '<td>' . $row['nombre'] . '</td>';
Wrap the text in an anchor (a) tag.
echo '<td>' . $row['nombre'] . '</td>';
You should also probably take a look at the W3schools HTML5 tutorial.
Just add the <a> to your HTML, and include the URL in it.
echo "<td><a href='script.php?id={$row['nombre']}'>{$row['nombre']}</a></td>";
echo "<td>
<a href='yourfile.php?subDom=$row['nombre']'</a>
</td>";
Then you can check for if link is clicked, you can trigger action for click. Like below:
if($_GET['whateverComingFromDB'] == "whatDoYouWantToCompare"){
//...Anything you want to happen after click the link
}

PHP and HTML Table Trouble adding target="_blank"

echo "<td>$row[instagram]</td>";
I am trying to add target="_blank" to that somewhere just so when I click the link it opens in a new tab, for the life of me I can't get it.. I've tried it everywhere and every way it would exhaust me to retype all of them but this is my current line.
Try this:
<a target=\"_blank\" href=\"https://www.instagram.com/" . $row['instagram'] . "\">$row[instagram]</a>
It will add the target attribute to _blank
try to use target='_blank'
echo "<td><a target='_blank' href=\"https://www.instagram.com/" . $row['instagram'] . "\">$row[instagram]</a></td>";

How to get the Text Value of a Clicked Link using PHP

I know it's very easy to get the text value of a link using jQuery.
But Isn't it possible to get the text value using only PHP? Please have a look at my code:
echo '<table>'
foreach($array['data']['results']['titles'] as $data) {
$title = $data['title'];
$id= $data['id'];
$url = $data['url'];
echo '<tr>';
echo '<td>' . ''.$title.'' . '</td>';
echo '<td>' . '<a href= ' .$url . ' target="_blank" >IMDb Link</a>' . '</td>';
echo '</tr>';
}
echo '</table>';
This picture shows the output of my code
Suppose the user clicked on the Third movie - Batman: The Animated Series. How do I make my movie.php page look like this -- (image below)
The Link Text (which is $title) should be passed to the movie.php page and also the IMDb Link of the corresponding movie (which is stored in the $url variable)
The Only way I know is using $_SESSION but it won't work in this case as it will only store & pass the last value of the foreach loop
Please help me in this regard. Thanks :)
Considering $id as the row ID for the particular movie from the Database. You can use url encoding over here. Your code must be
echo '<td>' . ''.$title.'' . '</td>';
When clicked your URL will look something like.
movie.php?id=3
On your movie.php file use $id = urldecode($_GET['id']); to get the movie ID and you can fetch the relevant data from the DB again.
Let me know if you have any issues.
Try sending all info with Proper Primary key OR here is runtime solution
echo '<td>' . ''.$title.'' . '</td>';
Don't forget to urlencode the variables
each link should contain the unique filed like $id so your url should be echo '<td>' . ''.$title.'' . '</td>';
You can pass the encoded value of $id so end user cannot guess the value.In movie.php you decode the $id& show information on the basis of $id

Same page Hyperlink with PHP

I would like to link to another part of a php page. So $x is a value I've pulled from an array that is a hyperlink.
echo "<a href='#{$x}'>{$x}</a>" . " ";
However I am stuck in linking to the target id on the same page.
echo '<a id="$x">' . '<h2>'.strtoupper(str_replace("_", " ",($x))).' ' . 'offers'.'</h2>'.'</a>';
Sure when I hover over the link, it is passing the correct value of $x in the query string, but not linking to the because I am coding the target id part wrong.
Any help appreciated.
Volterony
If you want to visit a ID on on the page use href="#id"
echo '' . '<h2>'.strtoupper(str_replace("_", " ",($x))).' ' . 'offers'.'</h2>'.'';
Improved Code
echo '<h2>'.strtoupper(str_replace("_", " ",($x))). 'offers </h2>';

pass link text to next page

For my actual web-project, I made a tagcloud. When I click on a tag, it should be passed to the page showRecipesFromTags.php.
<form name="tagform" id="tagform" method="get" action="/showRecipesFromTags.php">
<?php
include('php/getRandomTags.php');
$tagsarr = json_decode($return4634, true);
foreach ($tagsarr['Data']['Tag'] as $key => $tag11) {
echo '<a id="seastags" href="#" onclick="document.tagform.submit()"><font size="' . rand(1,4) .'">' . $tag11['Tag_name'] . '</font> <br/></a> ';
}
?>
</form>
It can already go to this page by clicking on the href, but what I need is to pass the id of the clicked tag. The name of the tag is called Tag_name. The name is shown but I donĀ“t know how the pass the id to the next site. The id is in my JSON array and is called Tag_id.
How can I manage this?
Why do you even need a form? Just use plain links.
Try using this in the foreach loop:
echo '<a id="seastags" href="/showRecipesFromTags.php?tagId=' .$tag11['Tag_id'] . '"><font size="' . rand(1,4) .'">' . $tag11['Tag_name'] . '</font> <br/></a> ';
Your choice are:
use a hidden field
put it in the URL
use a cookie

Categories