This question already has answers here:
Open link in new tab or window [duplicate]
(4 answers)
Closed 7 years ago.
and first off a thank you to all of the StackOverFlow users as I have found a lot of good answers here. I am a PHP/mySql newbie and I’m teaching myself from books and examples from others.
My problem: I have a mySQL DB with a URL column and a text column with a “clickme_text”, all the same DB row.
From my website I want to be able to hit the “clickme” and then the DB URL will open in a new tab.
Right now my PHP code works but it will not open the url in a new tab, it opens the new url in the same tab.
I’m sure the answer is already out there somewhere, but I’ve gone crossed eye’d trying to create the html and PHP to both go to the new url and open in a new tab.
My DB url is “picture_link” and my clickme text in the DB is “picture_text”.
This code pulls the url and the “clickme text just fine from my DB, but it opens the url in the same tab.
echo '<li>' . '' . $row['picture_text'] . '' . '</li>' . '<br/>';
I’ve tried a bunch of variations of something like this but it’s a no-go:
Echo ("<script> window.open(\""'<li>' . '' . $row['picture_text'] . '' . '</li>' . '"\");
I know this html will open a new tab to “google” (for example):
Click Me!
Do I need to create a var that points to my DB url, and then point my html to this var?
Any help on how to open my “clickme” DB url in a new tab is appreciated, thank you.
You need to add target="_blank" to your link.
echo '<li>' . '<a target="_blank" href="' . $row['picture_link'] . '">' . $row['picture_text'] . '</a>' . '</li>' . '<br/>';
Simply add target="_blank" to your generated link:
echo '<li>' . '<a target="_blank" href="' . $row['picture_link'] . '">' . $row['picture_text'] . '</a>' . '</li>' . '<br/>';
Ted,
You just need to add the target to your tag
echo '<li>' . '<a href="' . $row['picture_link'] . '" target=_blank>' . $row['picture_text'] . '</a>' . '</li>' . '<br/>';
Related
I am trying to open a bootstrap modal window containing product image and information. My problem appears to be the #uoc-modal inside the data-target. Can some please tell me how to correctly enter the data-taget id inside an echo?
echo '<a "data-toggle='modal'", "data-target='#uoc-modal'" href="' . get_the_permalink() . '">';
From your question code, you should escape it
echo '<a "data-toggle=\'modal\'", "data-target=\'#uoc-modal\'" href="\' . get_the_permalink() . \'">';
But, I think this should work
echo '<a data-toggle="modal" data-target="#uoc-modal" href="'.get_the_permalink().'">Modal</a>';
But anyways, you don't need data-target attribute for <a> element. Just use href instead.
Try this code:
echo '<a "data-toggle=\'modal\'", "data-target=\'#uoc-modal\'" href="\' . get_the_permalink() . \'">';
Good evening
I am working on a project that allows users to search Flickr and select certain images from the list of results which can then be viewed in a gallery. I'll write out the process that I have created so far and explain where I am stuck.
The index page is just a search bar and a submit button.
The user types in a search term and hits submit where the form action is action=flickrcall.php
flickrcall.php does this:
<?php
require_once('flickr.php');
$Flickr = new Flickr;
$data = $Flickr->search($_POST["search"]);
foreach($data['photos']['photo'] as $photo) {
echo '<img class="large" onclick="select(this)" src="' . 'http://farm' . $photo["farm"] . '.static.flickr.com/' . $photo["server"] . '/' . $photo["id"] . '_' . $photo["secret"] . '.jpg">';
}
?>
This will generate a list of image results up to whatever number I specify, right now it is 10. The outcome then is 10 of these:
<img class="large" id="test" onclick="select(this)" src="flickr.img.url.jpg" />
What I want to do is wrap the first <img> with then wrap the second <img> with and so on. (this is so I can use a CSS lightbox effect on the images later)
I think the way to do it is somehow create a variable (lets call it $hrefNumber) which will count up to however many results there are and use that variable like this in the echo statement above:
echo '<a href="#img' . $hrefNumber . '">
<img class="large" onclick="select(this)" src="' . 'http://farm' . $photo["farm"] . '.static.flickr.com/' . $photo["server"] . '/' . $photo["id"] . '_' . $photo["secret"] . '.jpg">'
</a>
;
The problem is that I do now know how to create such a variable nor where to declare/write it.
Does this make sense? Does it sound like I am on the right track or am I way off?
$counter=0;
foreach($data['photos']['photo'] as $photo) {
$counter++;
echo '';
}
or
foreach($data['photos']['photo'] as $counter => $photo) {
echo '';
}
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>';
I am trying to grab the ID of my link from every single one and output it to a db which i will then use to go and scrape the actual page.
So i will grab the id, curl the page link then parse the details.
So far i have my links clickable, it's just trying to get the certain part of my links that is the hard part.
I have tried $_GET['id'] but this won't work as the id's are not in that format.
Here is the way my links are set out:
download.php/1000338/The%20Rise%20and%20Fall%20of%20Legs%20Diamond%20%5B1960%5D.avi.torrent
what i want to grab is the 1000338 part but i want it to do this for every single one and ofcourse they are not the same.
Any help is very much appreciated, thanks.
$link="download.php/1000338/The%20Rise%20and%20Fall%20of%20Legs%20Diamond%20%5B1960%5D.avi.torrent";
$x=explode('/',$link);
$id=$x[1];
demo:http://codepad.viper-7.com/cWYXKe
using your code:
$rss = simplexml_load_file('RSS FEED HERE');
echo '<h1>'. $rss->channel->title . '</h1>';
foreach ($rss->channel->item as $item) {
//echo the link echo '<h2>' . $item->title . "</h2>";
//echo the date echo "<p>" . $item->pubDate . "</p>";
//echo the description echo "<p>" . $item->description . "</p>"
$x=explode('/',$item->link);
$id=$x[1];
}
then use $id any way you like
i have a website that provides chat service. i made member-information page for every member in chat. i want to display member-information to anyone who clicked at username in chat.
for example:
jack
hi
jhon
hi
jack
i'm jack
jhon
i'm jhon
here is the header
$chat_messages_html .= '<li>' . '<span class="chat_message_header">' . '' . $chat_message->username . ''
my problem how to get variable $chat_message->username in member information page to use it to retrieve information
i hope it is clear
Add user id to link:
$chat_messages_html .= '<li>' .
'<span class="chat_message_header">' .
'<a href="meeting/member_info?userid=' . $userid . '">' .
$chat_message->username .
'</a>'
Then you can retrieve user id using $_GET["userid"] in meeting/member_info.php.
And please consider using htmlspecialchars() to escape dangerous content.
You can pass it through the query string:
'' . $chat_message->username . ''