Jump to content

link id


manalnor

Recommended Posts

Hello dear friends,

 

Let say we have

 

$space ="hello world";

 

then remove spaces between the words by using

 

$title = str_replace(' ', '-', trim($space));

 

so it would be here as "hello-world"

 

and let say we have stored title,article text...whever in an database table that call back all this using id then for an article with id=1 its link will be

 

site.com/index.php?id=1

 

it is clear that the

 

echo "$id"; //<--- 1

 

now some wordpress or/and blogs using rewrite .htaccess to make the link as

 

site.com/$title-$id 

 

(as our example site.com/hello-world-1)

 

then how they know its $id = 1 to get any variables from database that needs the id

 

i've tried but never works and only works if i made something like

 

site.com/$title_$id  //<-- site.com/hello-word_1

 

cause it needs difference separate in order to understand the id

 

so how to make it ? how to make it understand that the last separated is the id

 

thanks

Link to comment
Share on other sites

The sites you are reffering to mainly use the MVC (Model View Controller) design pattern. this reflects in the URL. Each Controller has a set of Actions which take in the user parameters and pass them to the model etc.. Therefore if you are passing a variable through the url:

 

// www.somewebsite.com/ControllerName/ActionName/Variable1Name/Variable1Value/Variable2Name/Variable2value
// which translates looks like:
// www.somewebsite.com/Loginpage/loguserin/myusername/name1/password/logmein

 

obviuously you would not pass sensitive data like this, but i hope it explains it for you

Link to comment
Share on other sites

i found something...

 

if we make url like this

 

one-id.html <--- it works

 

but for

 

one-two-id.html <--- not working can't even know the id  :shrug:

 

and for

 

one-two_id.html <--- working this one can know the id

 

 

how then i can set it like second one

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.