I have a google map on this page, all markers were generated by submit postcodes. So I have the array below, loop info of each marker,
imploded as ("array", "array") format, I am trying to click on a infoWindow and display the according marker details on details.php.
The problem is everything is on the button onclick event, only a simple get on the second page.
This is working, but it is a very bad way. Because the limit to URL length and security reasons;
I would like to be able to get an array info from details.php page,
and the button onclick event trigger url looks like: details.php?marker=id
I don't know what is the best way to go about this, can someone pointing me to the right direction please?
index.php
$info = array();
foreach($stmt as $x)
{
$info[] =
"<h4>" . $x['name'] . "</h4><hr />".
"<h5>Address: </h5>" . $x['Address']."<br />" .
"<h5>Postcode: " . $x['postcode'] ."</h5><br />" .
"<button onclick='window.location.href= \\\"details.php?marker=". "<h4>" . $x['name'] . "</h4><hr />".
"<h5>Address: </h5>" . $x['address']."<br />" . "<h5>Postcode: " . $x['postcode'] ."</h5><br />" . "\\\" ' >
View Details</button>";
}
$i=' "'.implode('","', $info).'"';
details.php
echo $infomarker = $_GET['marker'];
You have to use $x['id'] insted of $x['name'] which is unique in your database and also use base64_encode() for encryption of your id "details.php?marker=".base64_encode($x['id'])."
In your details.php
$infomarker = base64_decode($_GET['marker']);
Try using AJAX to get the info from details.php and then load it into your InfoWindow.
I didn't realise how simple this was, all I need is use that id, write it inside a sql statement in details page then call any part of the statement out. Thanks everyone. Thanks to #Manjeet Barnala for encode tips.
Related
On my custom Single product page, I want to link every value of pa_ontwerper to the correct page. I used this code what works if pa_ontwerper has only 1 value:
$ont = $product->get_attribute('pa_ontwerper');
echo "<a href='https://www.website.nl/attribute" . $ont . "/'>" . $ont . "</a>" ;
This results in: designer1 with link to www.website.nl/attribute/designer1/
But when pa_ontwerper has for example 2 values, the output wil show something like:
designer1,designer2 with a link to www.website.nl/attribute/designer1,designer2/
Which is wrong.
What can I change in the code to make sure both values are linked correcly?
I have the follow two files and I would like to transmit information between the two files using a session, but I am not getting the right results. Here are the files
index.php:
<?php
session_start();
for ($i=0; $i<=2; $i++) {
echo ("<p><a href='getpage.php?row=$item_title' target='_blank'>" . $item_title . "</a>");
echo ("<br>");
echo ($item_desc . "</p>");
$_SESSION['item_link'] = $item_link;
$_SESSION['item_title'] = $item_title;
}
and the getpage.php has the following
<?php
session_start();
if (isset($_SESSION['item_link']) && isset($_SESSION['item_title'])) {
$item_link = $_SESSION['item_link'];
$item_title = $_SESSION['item_title'];
header( "Location: $item_link" );
}
But I keep getting the last item_link when I click the link and run the getpage.php file by clicking the link from the index file. How do I put the session into an array so that I am not only getting the last value in session after you click the link?
This is a quick drive-by attempt at an answer, but you might try
$_SESSION['item_link'][] = $item_link;
$_SESSION['item_title'][] = $item_title;
Then your session variables will themselves be arrays.
I suspect your code is based on a misunderstanding on the underlying mechanics. Files are nothing but static assets, nothing but a bunch of zeroes and ones that do nothing but use disk space until you do something with them.
Just printing the name of a file:
echo ("<p><a href='getpage.php?row=$item_title' target='_blank'>" . $item_title . "</a>");
... will neither execute the file nor load it in memory or assign any resource of variable to it. It's just text. Variables defined in the for-each-file loop will not transmit to the files. The source code in the file will eventually run when the user clicks on the link.
Secondly, that's not how PHP sessions work anyway. Session data is not attached to a specific file, it's session-wide information.
You appear to be partially aware of URL parameters. That's the proper way to transmit information as long as it isn't sensitive or too long. If you pass $item_title in the URL:
echo ("<p><a href='getpage.php?row=$item_title' target='_blank'>"
... it'll be available right at $_GET['row']. There's no need to fiddle with sessions:
$_SESSION['item_link'] = $item_link; // What for?
Last but not least, when you inject text into a string that's aimed to be consumed by a computer (such as a URL or an HTML document) you need to ensure you don't break the data format. PHP provides the following built-in tools:
For URLs: rawurlencode()
For HTML: htmlspecialchars()
So your echo should look like this:
echo ("<p><a href='getpage.php?row=" . htmlspecialchars(rawurlencode($item_title)) . "' target='_blank'>"
I have a SQL database that PHP is getting the contents of. It gets the info from each row of a table and displays it on a web page. There is also an anchor and a hidden div containing more details from that row of the SQL table. When the use clicks the anchor the jQuery needs to detect it and show the hidden div. The problem I have is that each anchor and hidden div have a dynamic id of:
'ev_a_' . $row['id']
'ev_' . $row['id']
the jQuery I assume needs to look something like this:
$('#ev_a_')[].click(function(){
$('#ev_')[].show();
}
I'm not entirely sure how this works and I've never used dynamic ids before in jQuery. Any suggestions?
I should point out the PHP/SQL code is:
while($row = mysql_fetch_array($q_result)){
echo "<br/><b>" . $row['a'] . "</b><br/>" . $row['b'] . ", " . $row['c'] . "<br/>" . $row['d'] . "<br/><a class='ev_event_a'>More Details</a><br/><div class='ev_event'>" . $row['e'] . "</div>";
}
I would use a class instead for these links instead and set the ID in a data attribute. Depending on your needs you don't even need the ID as you can show the next element if it is already part of the DOM.
A simple example (ID not used...):
Toggle details
<div class="initially_hidden">
...
</div>
....
Toggle details
<div class="initially_hidden">
...
</div>
....
and the javascript:
$('.show_more').on('click', function(e) {
e.preventDefault();
$(this).next().slideToggle();
// if you need the ID, you can get it via $(this).data('id')
});
I am trying to get the name of the person who has posted the post, but I don't understand how to get the name from the array.
Here is the full code:
http://pastebin.com/88ADm5Uw
This is the line I have a problem with:
echo "FROM: " . print_r($post['from']) . '<br>';
This line returns two values(id and name) and I want to only print out the name. Please help!:
EDIT:
Any way to get the profile picture?
Try this:
echo "FROM: " . print_r($post['from']['name']) . '<br>';
You can see the complete JSON here:
https://developers.facebook.com/tools/explorer?method=GET&path=me%2Fhome
$post['from'] is an array containing name and id. If you only want to print out the name, you could do something like echo $post['from']['name'] I believe.
For a little "webshop project" I create a table with PHP and echo"..." function. The table displays some values and in the last cells, there shall be a button which enables the user to delete the corresponding row (or better said, purchase). The data is held in a database and read out while the page loads and than displayed in the table.
I use a "purchase id" to find out which rows have to be deleted, and it works fine if I just implement the function itself. The problem is that I can't get the function working as "onclick" event for the button.
So, some code:
function delete_purchase($purchase_id){
mysql_query("DELETE FROM purchase WHERE purch_id = '$purchase_id'");};
That's the PHP function which deletes the rows, easy enough.
$result = mysql_query("SELECT purchase.purch_id, item.name, purchase.amount, purchase.purch_date, delivery.meaning, item.weight FROM purchase, item, delivery WHERE purchase.cust_id='$cust_id' AND delivery.del_id = purchase.delivered AND purchase.item_id = item.item_id");
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['amount'] . "</td>";
echo "<td>" . $row['weight'] * $row['amount'] . "</td>";
echo "<td>" . $row['purch_date'] . "</td>";
echo "<td>" . $row['meaning'] . "</td>";
echo "<td><button onclick=\"delete_purchase('" . $row['purch_id'] . "')\">Kill</button></td>";
echo "</tr>";
}
And this is the part which doesn't seem to work. I get the variable and some other values from the database and insert them into my table as long as there are values. Everything is displayed, even the buttons; but clicking on them doesn't do anything.
Source code of the website seems fine:
<td><button onclick="delete_purchase('138')">Kill</button></td>
Hope everything's clear, and you guys have some ideas what's wrong. If you need to know additional stuff, just ask and I'll see what I can do.
onclick="delete_purchase('138')"
calls a Javascript function called delete_purchase, which doesn't seem to exist in your code. You only have a PHP function with that name.
Since all PHP is executed on the server side, the HTML will be built long before the client ever sees the code and therefore you will never be able to call the delete_purchase PHP function from the client side.
The only two ways to get around this are:
- Create a delete_purchase JS function that then calls a PHP file through the use of AJAX.
- Don't call the onclick JS function at all and make the button a regular form submit that you then catch on the server side to delete the purchase. This however would involve a complete page refresh.
Your delete_purchase() function is defined in server-side which is not available in client side. You need to send a request to server and send the id, for example:
?action=delete&id=1
Then you can validate it on server side and call the function
<?php
if(isset($_GET['action']) && $_GET['action'] == 'delete'){
//do some staff
}
?>
you try to call a PHP-function directly from HTML (from browser)
this is impossible!
you may call it using 2 ways:
1) AJAX-call of php-script which will delete the purchase
2) redirect browser to php-script which will delete the purchase and then redirects you back