I use a SQL database and a WHILE LOOP to display the contents of the database on the main page and am currently trying to incorporate a Facebook "like" button for each and every item on the page.
Currently every item listed in the database is displayed on Shopping.php
I need the server to be able to create a page with a unique address for each item in the database so that the "like" buttons don't all link back to the Shopping.php page.
What I am imagining is something like "/Shopping.php?item=0001" that will link to a page dedicated to that one single item.
Thanks for your time.
Please if you could give a code how to do it , it would be great help
if(isset($_GET["item"]))
{
// Fetch information about item with ID = $_GET["item"] from database and render a page for it.
}
Was that what you were looking for?
Yes this would work, only change is, you need to get the item number from the URL and refine your SQL query.
if(isset($_GET["item"]){
sql = "select * from items where item_id = $_GET['item']";
\\display results after executing this sql
}
But if you want to optimize it to search engine, i recommend you keep your urls as
shopping/item1
shopping/item2 etc
Related
I am building an admin type script to view records within a mySQL database. This links in numerous tables and is all working perfect. I have now added a filter form to allow me to search/filter for records that match specific criteria. Again this works perfect.
The problem I cannot get my head around is this...
For each record I have a link that allows me to go into that record and view more information/perform tasks on the record.
Initially it was simple to have a 'Previous' and 'Next' link for cycling through the records which meant I didnt need to go Back to the search results to go to the previous/next record. It simply +1 or -1 from the current record ID to generate the link.
Now however I am filtering so the records ID's might be 1,3,4,5,8,10,15,30 etc
The problem is now that once I click into any one of the results to view that record I essentially lose the filtering and all of the results.
The only way I can think of achieving this is to pass the filter variables in with the link and redo the filtering every time the View page is loaded, working out where the current record is in the result set and creating a link based on the previous and next records in the result set.
Am I doing this correct or is there a better way?
I have searched but most answers are geared towards the basics of looping through mySQL query results which sounds the same but is very different.
Any advice would be greatlt appreciated!
I have a html page listing all the jobs in my database, I managed to get everything displaying on www.mysite/alljobs.php (or the list all records page), great, but I cannot get hold of the different id's from this page to display on a dynamic link to showing the job details for each job i.e www.mysite/thejob.php?job_id=8 (the specific record details page).
I have recently had to upgrade my PHP version to PHP7 and need to use MYSQLI with PHP. Can any help with the code I need for both the list page and the details page so that dynamic pages are created when I click on the alljobs.php links.
You can loop over your query results and print out the ID for each one in a link, like this
<?php
foreach ($myQueryResults as $item){
?>
Link
<?php
}
?>
If you're using <a> per record, you could put the id in the href, something like this:
Link
you can pass your id variable in php quote with echo
View
you can send the id on link url and the get with $jobID = <?php $_GET['id']?>on that page. Don't forget to sanitize.
Details
I want to keep page in search form and when I visit another page and return to previous to see only what I search.
For example, I have page with table, in that table I have list of all products which is 30 products. When I submit search query for some word and get per instance 5 products, I want to keep that and visit all another pages and when I back on product page to see again only that 5 products.
Any help?
You're looking for a way to store dynamic data. Your best bet would be to use something like Sessions or LocalStorage
How I add pages for my website without create files for any page I want. To make understand let's say I need a details information page to read from mysql the rest of informaton of a specific ID BUT! in link i don't want to be with id
(site.com/details-product-idnumber)
i want to be only
(site.com/details-product-nameofproduct)
I know basicly this need to be rewrite from .htaccess but what I need to know about this function/system.
Another example is wordpress blog platform, when you add a post, in link it only the title of the ID post from mysql, what php code i need to use or what's the name of this function. Thanks.
may be you can use a unique_name (in your application a unique name for a product).. in your database table.. and just pass that unique_name in the link..
like..
site.com/details-product-unique_name
and your sql query should be like..
select * from product where unique_name = '$_GET["your_get_field"]';
let me know if you want any further guidance...
i found it difficult,,,, fetching data from database while a buttons are randomly generated in for each how can i fetch
Without understanding what your question really is, you could go trough the mysql query result like this:
// button_text is a database column in this example
while ($row = mysql_fetch_row($result)){
echo "<button type="button">".$row['button_text']."</button>";
}
But to really help you, you need to rephrase your question!
I'll make some assumptions for what you are trying to do:
1. You have buttons that fetch more info from a db
2. The buttons are "randomly" generated, and each calls different info (pets, cars, etc).
You may or may not be using ajax, but I will describe it basically assuming straight php, and you are using a single page (for clarity in my explanation).
What you need to do is have each button either be a link or a submit for a form. This just depends on whether you want to use GET or POST. The buttons will have php generated links (if GET) or values (if POST). For example, using get the link could be "www.file.php?cat=cars". The button would just have the value of "Cars", and since bother are generated, that shouldn't be an issue keeping them the same.
When the page is now reloaded based on the click, the top of the page has a query in it to get the new info. For example, it would run a query looking for all items that have the car category. Then the new information would be displayed, and the new random buttons would show.
VERY IMPORTANT: Sanitize all GET and POST values before using them in a query