I use pagination class to generate the following table, book titles are stored in a database
Title Action
New book for you Edit Delete
How to become a manager Edit Delete
Learn PHP in 10 minutes Edit Delete
< 1 2 3...10 Last>
Each Edit or Delete is a link created as Edit
In order to move to the edit page to update book title (edit and save into mysql table) that I need to use $_GET to retrieve $title of the correct clicked Edit link, I wonder how the href in case of a single page likely to be href='book/details?title=$title' becomes ?
If you generate your Markup through PHP you could do as you said.
foreach ($titles as $title) {
echo 'title';
}
Otherwise you would just type the url in your href.
<a href="book/details?title=actualTitleName">
and get it serverside with
$_GET["title"]
Related
I have a anchor tag and I would like it to pass GET data into the URL so I can access that data from a php script.
Here is an example
<a href="template.php" GET="product1"/>
<a href="template.php" GET="product2"/>
The above code does not work so I imagine that is not how it is done.
What I am trying to do is pass the GET data to template.php so it can display things depending on what the user clicks and what get data is sent.
Just create a querystring with a key that has meaning to you (I chose "item") and assign it the product key as the value:
Product 1
Now when a user clicks on that link you will have a $_GET variable of product1:
$item = $_GET['item']; // product1
Like this:
product1
Been struggling with this problem for a while now and I just can't het my brain to understand it.
I have a very simple website where I can add items in a database. There is a list on index.php where the list is displayed and each item needs a url that directs to a "more information" page.
The "more information" page has to be a dynamic one as there are a lot of items and these items can be added or deletend.
What my code for this section looks like at the moment:
$result_set = mysql_query("SELECT id, name FROM items WHERE id = $item");
while ($item = mysql_fetch_row($result_set)) {
$name = $item['name'];
echo "$name";
This results in a link if item 1 = wrench ../items/wrench.html.
But this page obviously doesn't excist. How can I get this to work?
You can't have one html page for each item if the items are dynamically added
But you can do it this way
echo '$name';
This way you have only one page who receive as a GET parameter the id of the item you want the description.
In the page of more_information.php you just display a text corresponding to the id you received.
use .htaccess for this.
you can add this code
RewriteEngine On
RewriteRule ^items/(.+)$ items.php?page=$1
In your items.php use $items=$_GET[page]; so you can read what is in url after items/
This is a link where you can find more about RewriteRule's http://httpd.apache.org/docs/current/rewrite/intro.html
I'm looking to build a site which will have multiple options, for example;
NOTE** These are images not any forms or input type
Pick from one of the 5 images
Pick from one of the 3 images
Pick from one of the 2 images
Pick from one of the 6 images
and so on...
What I need to do is record which option (image) the user clicked on and then output a message.
For example if you picked a b c d, msg = hello
I'm not sure how to record this data, thanks!
You could link each image to a seperate page or reload the current page with a query string appended for example adding the following to your images as links
<img src="set1-image3.png" />
You could then save this information using PHP by processing only if the GET string contains the parameters image and set and could then split out which set/image has been clicked this way.
You could also use this to choose which image set to show on the screen (show set 2 if set=1 is in the query string etc.)
Using $_GET['set'] and $_GET['image'] you would have access to this information very easily in PHP.
For example you could do:
if( isset($_GET['image']) && isset($_GET['set']) ) {
echo "You clicked image" . $_GET['image'] . " from set " . $_GET['set'];
}
That would be the only pure PHP answer. The other way to do this is with Ajax or JavaScript but I'm guessing by your part about it being done in PHP this may not be what you want.
You could add a parameter to the link you click.
For example <img>
In page2.php you could read that variable using:
$_REQUEST["clickedImage"]
For example:
<p>The clicked image is: <?php echo $_REQUEST["clickedImage"] ?>
I have a PHP system that have orders, and items related to orders,
So I want to print every item related to specific order, without open the file.
I'm using a SQL query to show the pages:
SELECT * FROM items WHERE order_id = ".$oid.";
to collect items from this order and for each one, I write
<a href="view.php?iid=<?php echo $theResult['id'];?>" target="_blank">
Item <?php echo $theResult;?>
</a>
So the page view.php is a default that receive item_id in $_GET and build the page as I want.
There's no problem until here, BUT:
I want to print any result for view.php, for each item in order, without have to open and click to print everyone.
If you insist on still using the single view file view.php, a bit of a hacky solution could look like this:
<?php
foreach ($items as $iid) {
$_GET["iid"] = $iid;
require("view.php"); //This will print whatever the view.php page does
}
?>
Here $items specifies an array full of the ID's from the database.
By setting $_GET["iid"] to the id which we'd get from our database ($iid) and then including view.php, you can emulate a call to the file (and hence we'd print the view.php page for every item in the database).
If this is not what you want, it'd be awesome with some more info so we can help you along the way.
In a php project I need to add items to database, list them & allow the user to edit & update items using a single page.
This is my code to edit item link in HTML table
echo ' Edit ';
When a user click on the above link I need to hide Add button and display two new buttons to Update & Cancel the edit + display selected item name in a Text box to Edit.
To hide and display buttons I'm using jQuery and to display the item name i need to use PHP.
Here when i put PHP code and reload the page with $_SERVER['PHP_SELF'] (as in above code), hiding & displying of buttons is lost after the page load. (If I remove the _SERVER['PHP_SELF'] code from link it hides and display buttons as expected (but no php code run))
How can I retain the page update by Javascript and run the PHP code?
I'm new to PHP am I missing something in my code?
$_SERVER['PHP_SELF'] is only a refrence to the php document itself, it doesnt contain any key/value pairs. try using:
echo '<a href=" '.$_SERVER['PHP_SELF'].'?'. $_SERVER['QUERY_STRING'].
'&name=edit&id=' .$rowCountry->CountryId .
' " id="edit" onClick="MyFunction()"> Edit </a>';
edit:
i may have misunderstood the question. you may need something like this:
<?php
if(!empty($_GET[edit])){
//echo code that u want to show AFTER they click the edit link
}else{
//echo the code to show if they have NOT clicked the edit link
}
?>