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.
Related
I have a php file results.php with a grid of different items (each item is a row from the result of a certain query). When I click an item it takes me to another php file details.php where I want to show more details in the new page about the specific item I clicked.
function showAsItem($row) {
$defaultValue = $row[1];
$itemClassname="item";
$titleClassname="title";
$imageClassname="image";
$infoClassname="infolist";
$link="details.php";
$target="_top";
$img="https://barcelonando.com/es/wp-content/uploads/2012/12/barceloneta.jpg";
$alt="Imagen de $row";
echo '<div class="'.$itemClassname.'">';
echo '<div class="' .$titleClassname. '">';
echo '' .ucfirst($row[0]). '';
echo '</div>';
echo '<div class="' .$imageClassname. '">';
echo '<a href="' .$link. '" target="' .$target. '">';
echo '<img src="' .$img. '" alt="' .$alt. '"/>';
echo '</a>';
echo '</div>';
echo '<div class="' .$infoClassname. '">';
echo '<ul>';
echo '<li> Población: ' .$row[1]. '</li>';
echo '<li> Esperanza de vida: ' .$defaultValue. '</li>';
echo '<li> Inmigrantes: ' .$defaultValue. '</li>';
echo '<li> Transportes: ' .$defaultValue. '</li>';
echo '<li> Accidentes: ' .$defaultValue. '</li>';
echo '</ul>';
echo '</div>';
echo '</div>';
}
I only know how to send info from one webpage to another when it is an input type, but in this case I want to send the item static info (I just need to send the name of the item I clicked). Any idea about how to do it?
As #pavel pointed out, using a URL parameter should work for you. Every item must have a unique number or name associated with them.
Do not use their array index or similar, because that will change in the future.
Your example code has $row use numeric indexes - whichever one of them is unique you can use as a URL parameter. If you don't have one, you have to create one. Preferably one that will not change when the data is updated. That is where databases will use numeric IDs, but you can use a string as well, as long as you can identify the item from the details.php.
Example link: $link="details.php?id=" . $row[2];. Replace 2 with whatever is a unique number / name for every row.
Instead of only supplying the $row in your function, you can supply the row's ID as a separate parameter if that is what you need. Depends on how you organized this outside of your example code.
In this case you change the function as well:
function showAsItem($row, $rowId) {
// ...
$link="details.php?id=" . $rowId;
// ...
}
In details.php you can access this variable with $_GET: https://www.php.net/manual/en/reserved.variables.get.php
$id = $_GET['id'];
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 have a page full of products and when the page reloads after the add to cart button has been clicked i want to display a check mark next to the product that was added.
Using the rows and columns count i have assigned each product it's own class, for example
<div class = "location12">
I passed the location via post when the add to cart button is pressed so i can tell which div the button press was from and i can then use that data as an identifier.
I can get the page to scroll back to this position by referencing the div, but i'm struggling to get the image to only display on that one product. It will display on that product and then every product after it because it echoes on every time it loops after the first output.
Already added to the individual product page, but they want the same function as here: http://confettibox.ch/1-NEWSTORE/index.php?main_page=product_info&cPath=576_578&products_id=1265&language=en
on this page here:
http://confettibox.ch/1-NEWSTORE/index.php?main_page=index&cPath=4_586
Add to cart button submit is coded here, and you can see where i added the hidden field to pass the id of the div
$lc_button= '<div class="back">' . zen_draw_form_prod_list('cart_quantity', preg_replace($pattern, $replacement, $string), 'post', 'enctype="multipart/form-data"') . '</div><div class="back qty_bg"><input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($listing->fields['products_id'])) . '" maxlength="6" size="4" /><br />' . zen_draw_hidden_field('products_id', $listing->fields['products_id']) . zen_draw_hidden_field('div_id', $colcount.$rows) . '</div><div class="forward">' . zen_image_submit('button_add.jpg', BUTTON_IN_CART_ALT) . '</form></div><br class="clearBoth">';
I added the $_POST result to a session var here:
$_SESSION['location'] = (int)$_POST['div_id'];
And then used:
if ($messageStack->size('listing') > 0 && $_SESSION['location'] == $colcount.$rows) {
so that the messageStack output (success checkmark) would only display for that one product... except it displays for everything after it too :|
Products are output using this code:
if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') {
$lc_text = implode('<br />', $product_contents);
$list_box_contents[$rows][$column] = array('params' => 'class="centerBoxContentsProducts centeredContent back featured'. $column .'"' . ' ' . 'style="width:235px;"',
'text' => $lc_text = '
<div class="prod_table">
<div class="prod_image">' . zen_image(DIR_WS_IMAGES . $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTH, IMAGE_PRODUCT_LISTING_HEIGHT, 'class="listingProductImage"') . '</div>
<div class="prod_name">' . $listing->fields['products_name'] . '</div>
<div class="prod_price back">'. zen_get_products_display_price($listing->fields['products_id']) .'</div>
<div class = "location'. $colcount.$rows .'">'.$success.' </div>
<div class="prod_content forward">'. $the_button .'</div>
</div>
');
$column ++;
$colcount=$column;
if ($column >= PRODUCT_LISTING_COLUMNS_PER_ROW) {
$column = 0;
$rows ++;
}
}
// End of Code fragment for Column Layout (Grid Layout) option in add on module
$listing->MoveNext();
$success is where i want the check to be output.
How can i echo the success message to only 'location12' ?
Is it even possible?
You haven't posted much code but I'll try answering.
You can do it either with Javascript or PHP.
With Javascript/jQuery you can set the background image of any div you want:
$('.location12').css("background-image", "url(/myimage.jpg)");
With PHP you need to count your iterations and only echo the image on $index==12.
I do not know if you are using foreach, for, while or any other method.
Assuming it is a foreach loop you can do the following:
$index = 1;
foreach ($products as $product) {
if ($index == 12) {echo "<img src=''/>"}
$index++;
}
As you can see, the jQuery method is easier.
Hope this helps!
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
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