php pages in mysql link without id - php

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...

Related

How can I create a unique link that auto-fills a form in php?

I have a .php web form that I would like to append a string from a sql database to the url that can be clicked that is associated with the sql string. Any help would be greatly appreciated! For example, twitter.com/mrgoolboy. The username appended to the url associates content on that page with the data relating to the username.
You need to do 4 steps to achieve that.
Create text field in database table permalink
Ask to user to set his/her username or permalink twitter.com/#naveedramzan here naveedramzan is permalink. Here you can add your auto-fill form for URL.
Update .htaccess to parse permalink and open relevant file
In database query, instead of filter record based on id, you need to do filter based on permalink field

Pretty urls codeigniter

I have the following situation, I have some posts on my website which are access by id, lets say for example
http://websiteurl.com/posts/see/1
the posts controller, has a see method which looks for the id on the database, lets say it find it and the posts title is "Most amazing photos" , how could i configure the Route.php class of codeigniter so that this posts its accessible from an url similar to:
http://websiteurl.com/posts/see/most-amazing-photos-1.html
this posts are created dynamically and they are a lot, so setting one by one manually is not possible.
Thanks!
What you can do is use regex. Assuming that you will be creating different url tag for each photo you can have something like this in you route.php
$route['posts/see/(:any)'] = "posts/see/$1";
However it is necessary that you have unique url-tag for each photo otherwise it will be ambiguous to fetch photo from the url-tag.
Have it a go.
The url parameter you would like to achieve is called a slug
like wordpress does, you can query the POST via its id or its slug.
One way to implement this is every time a post is created, you save the slug to the db.the slug can be the title of the post or anything readable for SEO. So that everytime a user visits the site, your controller method may prcess the parameter if it is a slug or an id and continue the query using the given parameters.
then you can set up the routes like:
$route['posts/see/(:any)'] = "posts/see/$1";

Codeigniter Route ID

I've built a webpage that, in its products page has this prototype for its url
http://www.example.com/products/show/some-really-nice-product/512
The last bit of the url is the product id, which serves the sole purpose of searching the db for the product.
But, is it possible, using routing, to be able to hide that part and still be possible to search the product by its id?
Like
http://www.example.com/products/show/some-really-nice-product/ ??
Thank you
If you don't want to put a number in your URL, you can't later search by a number/id :)
So you could add a VARCHAR field to the table, say "urlized", and use "some-really-nice-product" as its content for the given ID (you'll need to 'urlize' all your product names and make them unique). Don't forget to index your new field...
Then, you could access the product page using this URL which is very SEO friendly (ends with ".html"):
http://www.example.com/products/show/some-really-nice-product.html
...by adding a route to CodeIgniter, somehow like this:
$route['^products/show/(.*).html'] = 'products/show/$1';
In your controller/model, search the database for the string that is passed to "show" method, instead of the ID
if you hide id you can't retrieve that from the url anymore
if you want to hide that anyway just do:
$route['products/show/(:any)'] = "products/show/$1/$2";

Populating PHP page with MySQL info from a variable in the URL

I'm trying to create unique urls for user's of a site I'm designing. Basically I want the url to look like this:
http://www.example.com/page.php?user_id=3
Or whatever user_id they are assigned. Basically I want user to be able to go to that url and it generates the page with the info (first name, last name, etc.) of the user from the row in the MySQL table with that user id number. I know that creating the URL would be done by $_GET but this is sort of backwards from that. I want them to be able to go to the URL and the pages gets the variables from the URL.
Sorry if this is basic, I'm having trouble searching for an answer because it always gives me the answer on how to submit a form TO the URL not FROM the URL. Thanks for all the help.
$user_id = $_GET['user_id'];
you could use this to get the variable.And then search the database for the matching id and get get all the details.
Since you want to contain all the details in you form.You could keep adding the other elements like this.
http://www.example.com/page.php?user_id=3&first_name=Max&last_name=Payne
Using $_GET[which element you want the value of]
Accessing the get variables on the page is really simple!.In your case as you want to access the user id,you can get from $_GET['user_id'] and fire the respective query to fetch the user details to populate the page.For more reference you could check here
http://php.net/manual/en/reserved.variables.get.php

Dynamic URL WITH EACH PAGE having Shopping.php?item=0001

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

Categories