MySQL Question

get post id from long url (php)

hello i have post url like that


news.php? = news template

2 in (post =2 ) = post id in mysql
and test-title-test is article title

i want to get only post id to use it on mysql order and load content order by id


when i trying to use $id = $_GET['post'];
it echos 2/test-title-test
i need to echo only id 2

are there any other ways to get post id from url tu use it for mysql order?

Answer Source

You need to split the post-param.

Pre PHP 5.5:

$postParts = explode('/', $_GET['post']);
$postId    = $postParts[0];

PHP 5.5+:

$postId = explode('/', $_GET['post'])[0];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download