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
Related
I would know how to take the value on onclik for inject inside a sql request.
This code below create a link. When I click on the link a specific table appear
$value can two elements
$value['name']
$value['option_id']
$i = 0;
foreach($option_attributes_name as $value) {
$content .= '<li class="col-md-12"><a class="showTabOption nav-link" data-tableid="' . $i . '" data-toggle="tooltip" data-target="#section_ProductsOptionApp_content" href="'. CLICSHOPPING::link('index.php?&pID='. $_GET['pID'] .'#tab-option'. $i .'&toto=' . $value['option_id']) .'"><i class="fas fa-minus-circle"></i> '. $value['name'] .'</a></li>';
$i++;
}
In my table I have a specific dropdown to display information.
Currently it take all informations by the mysql request, but than I tried to make, it's a dropdown must take only the information on the value onclick ( .'&toto=' . $value['option_id'])
On onclick, how to take the value '&toto=' . $value['option_id'] to reinject inside the request.
Ajax page ?
I don't know if I am clear. If not I will complete this explanation.
Thank you.
I'm trying to be able to get place as a variable to use on page.php. It will start to load options into the select box for about 5 seconds and I'll actually be able to see the options, then it all deletes and I have an empty select box. Here's the PHP code:
<?php
$xml = simplexml_load_file("file.xml");
echo '<form method="get" action="page.php"><select name="place" id="place">';
foreach($xml as $banana)
{
if(isset($banana->id))
{
$id = $banana->id;
$string = $banana->state . " - " . $banana->name;
echo '<option value="' . $id . '">' . $string . '</option>';
}
}
echo "</select>";
echo '<input type="submit" /></form>';
?>
I know for sure that my XML is formatted correctly, but the XML file has a little over 2500 entries that each looks something like this:
<container>
<id>theId</id>
<state>theState</state>
<name>theName</name>
</container>
Any ideas why won't load?
Note: Some items have an empty id in the XML file, and I don't want to include those files, that's why I check to make sure it's set.
A couple things
Disable any javascript and try again--something may be binding to overriding the select box or the id of an element in it.
You generally want to properly escape text you pull in before inserting it into a HTML document in case there's a <, >, or such in it
Try the following:
echo '<option value="' . htmlspecialchars($id) . '">' . htmlspecialchars($string) . '</option>';
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
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 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