How to create clean url fetching data from mysql in php?











up vote
1
down vote

favorite












I want to know how to create url directly dynamically fetching data from mysql in php?



Let assume I have a database table named "Products":



1) id
2) seller_id
3) Product Code
4) Product Image
5) Product Description



  • Let assume there are 5000 products added in it or more.

  • Let assume my domain name is: www.xyz.com


Now what I want is to create urls from product table's seller ids like www.xyz.com/sellerid1



If new seller id added then I will get url dynamically automatically and on that page get all related products related to seller_id from table "Products"



I want url like



www.xyz.com/sellerid1
www.xyz.com/sellerid2
www.xyz.com/sellerid3


My File Name is where I want to fecth data from "Products" table: seller.php



I dont want url like:



www.xyz.com/seller.php?id=sellerid1
www.xyz.com/seller.php?id=sellerid2
www.xyz.com/seller.php?id=sellerid3


I want if someone hit the url directly on addressbar like: www.xyz.com/sellerid1 then all the products related to sellerid will show. It can achieve this by www.xyz.com/seller.php?id=sellerid1 but no user will remember that type of url. I want www.xyz.com/sellerid1



Sorry, two questions in one but I have no idea how to achive this dynamically.



Any idea or suggestions would be welcome.










share|improve this question
























  • Can you use .htaccess? Check this link: stackoverflow.com/questions/16388959/url-rewriting-with-php
    – Van Tho
    Nov 15 at 6:00










  • @ Van Tho , Thanks for the reply. Yes, I can use . htaccess but wiil it remove .php from all urls? Actually This is my first project so I never use .htaccess. And how to create url from database and show all related products this is the first task I have to finish.
    – Sarah
    Nov 15 at 6:09










  • Possible duplicate of How can I create a dynamic URL in php?
    – Thomas Jeriko
    Nov 15 at 6:15










  • @Thomas Jeriko, exactly like the question you have suggested I am also confused - The thing is, I don't understand how I can pass the $sellerid from the url to the php itself dynamically. Like www.xyz.com/sellerid1
    – Sarah
    Nov 15 at 6:17






  • 1




    @Sarah Why don't you use a framework like laravel or codeignitor?
    – Jestin Sebastian
    Nov 15 at 6:30















up vote
1
down vote

favorite












I want to know how to create url directly dynamically fetching data from mysql in php?



Let assume I have a database table named "Products":



1) id
2) seller_id
3) Product Code
4) Product Image
5) Product Description



  • Let assume there are 5000 products added in it or more.

  • Let assume my domain name is: www.xyz.com


Now what I want is to create urls from product table's seller ids like www.xyz.com/sellerid1



If new seller id added then I will get url dynamically automatically and on that page get all related products related to seller_id from table "Products"



I want url like



www.xyz.com/sellerid1
www.xyz.com/sellerid2
www.xyz.com/sellerid3


My File Name is where I want to fecth data from "Products" table: seller.php



I dont want url like:



www.xyz.com/seller.php?id=sellerid1
www.xyz.com/seller.php?id=sellerid2
www.xyz.com/seller.php?id=sellerid3


I want if someone hit the url directly on addressbar like: www.xyz.com/sellerid1 then all the products related to sellerid will show. It can achieve this by www.xyz.com/seller.php?id=sellerid1 but no user will remember that type of url. I want www.xyz.com/sellerid1



Sorry, two questions in one but I have no idea how to achive this dynamically.



Any idea or suggestions would be welcome.










share|improve this question
























  • Can you use .htaccess? Check this link: stackoverflow.com/questions/16388959/url-rewriting-with-php
    – Van Tho
    Nov 15 at 6:00










  • @ Van Tho , Thanks for the reply. Yes, I can use . htaccess but wiil it remove .php from all urls? Actually This is my first project so I never use .htaccess. And how to create url from database and show all related products this is the first task I have to finish.
    – Sarah
    Nov 15 at 6:09










  • Possible duplicate of How can I create a dynamic URL in php?
    – Thomas Jeriko
    Nov 15 at 6:15










  • @Thomas Jeriko, exactly like the question you have suggested I am also confused - The thing is, I don't understand how I can pass the $sellerid from the url to the php itself dynamically. Like www.xyz.com/sellerid1
    – Sarah
    Nov 15 at 6:17






  • 1




    @Sarah Why don't you use a framework like laravel or codeignitor?
    – Jestin Sebastian
    Nov 15 at 6:30













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I want to know how to create url directly dynamically fetching data from mysql in php?



Let assume I have a database table named "Products":



1) id
2) seller_id
3) Product Code
4) Product Image
5) Product Description



  • Let assume there are 5000 products added in it or more.

  • Let assume my domain name is: www.xyz.com


Now what I want is to create urls from product table's seller ids like www.xyz.com/sellerid1



If new seller id added then I will get url dynamically automatically and on that page get all related products related to seller_id from table "Products"



I want url like



www.xyz.com/sellerid1
www.xyz.com/sellerid2
www.xyz.com/sellerid3


My File Name is where I want to fecth data from "Products" table: seller.php



I dont want url like:



www.xyz.com/seller.php?id=sellerid1
www.xyz.com/seller.php?id=sellerid2
www.xyz.com/seller.php?id=sellerid3


I want if someone hit the url directly on addressbar like: www.xyz.com/sellerid1 then all the products related to sellerid will show. It can achieve this by www.xyz.com/seller.php?id=sellerid1 but no user will remember that type of url. I want www.xyz.com/sellerid1



Sorry, two questions in one but I have no idea how to achive this dynamically.



Any idea or suggestions would be welcome.










share|improve this question















I want to know how to create url directly dynamically fetching data from mysql in php?



Let assume I have a database table named "Products":



1) id
2) seller_id
3) Product Code
4) Product Image
5) Product Description



  • Let assume there are 5000 products added in it or more.

  • Let assume my domain name is: www.xyz.com


Now what I want is to create urls from product table's seller ids like www.xyz.com/sellerid1



If new seller id added then I will get url dynamically automatically and on that page get all related products related to seller_id from table "Products"



I want url like



www.xyz.com/sellerid1
www.xyz.com/sellerid2
www.xyz.com/sellerid3


My File Name is where I want to fecth data from "Products" table: seller.php



I dont want url like:



www.xyz.com/seller.php?id=sellerid1
www.xyz.com/seller.php?id=sellerid2
www.xyz.com/seller.php?id=sellerid3


I want if someone hit the url directly on addressbar like: www.xyz.com/sellerid1 then all the products related to sellerid will show. It can achieve this by www.xyz.com/seller.php?id=sellerid1 but no user will remember that type of url. I want www.xyz.com/sellerid1



Sorry, two questions in one but I have no idea how to achive this dynamically.



Any idea or suggestions would be welcome.







javascript php jquery mysql mysqli






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 at 6:27

























asked Nov 15 at 5:53









Sarah

1486




1486












  • Can you use .htaccess? Check this link: stackoverflow.com/questions/16388959/url-rewriting-with-php
    – Van Tho
    Nov 15 at 6:00










  • @ Van Tho , Thanks for the reply. Yes, I can use . htaccess but wiil it remove .php from all urls? Actually This is my first project so I never use .htaccess. And how to create url from database and show all related products this is the first task I have to finish.
    – Sarah
    Nov 15 at 6:09










  • Possible duplicate of How can I create a dynamic URL in php?
    – Thomas Jeriko
    Nov 15 at 6:15










  • @Thomas Jeriko, exactly like the question you have suggested I am also confused - The thing is, I don't understand how I can pass the $sellerid from the url to the php itself dynamically. Like www.xyz.com/sellerid1
    – Sarah
    Nov 15 at 6:17






  • 1




    @Sarah Why don't you use a framework like laravel or codeignitor?
    – Jestin Sebastian
    Nov 15 at 6:30


















  • Can you use .htaccess? Check this link: stackoverflow.com/questions/16388959/url-rewriting-with-php
    – Van Tho
    Nov 15 at 6:00










  • @ Van Tho , Thanks for the reply. Yes, I can use . htaccess but wiil it remove .php from all urls? Actually This is my first project so I never use .htaccess. And how to create url from database and show all related products this is the first task I have to finish.
    – Sarah
    Nov 15 at 6:09










  • Possible duplicate of How can I create a dynamic URL in php?
    – Thomas Jeriko
    Nov 15 at 6:15










  • @Thomas Jeriko, exactly like the question you have suggested I am also confused - The thing is, I don't understand how I can pass the $sellerid from the url to the php itself dynamically. Like www.xyz.com/sellerid1
    – Sarah
    Nov 15 at 6:17






  • 1




    @Sarah Why don't you use a framework like laravel or codeignitor?
    – Jestin Sebastian
    Nov 15 at 6:30
















Can you use .htaccess? Check this link: stackoverflow.com/questions/16388959/url-rewriting-with-php
– Van Tho
Nov 15 at 6:00




Can you use .htaccess? Check this link: stackoverflow.com/questions/16388959/url-rewriting-with-php
– Van Tho
Nov 15 at 6:00












@ Van Tho , Thanks for the reply. Yes, I can use . htaccess but wiil it remove .php from all urls? Actually This is my first project so I never use .htaccess. And how to create url from database and show all related products this is the first task I have to finish.
– Sarah
Nov 15 at 6:09




@ Van Tho , Thanks for the reply. Yes, I can use . htaccess but wiil it remove .php from all urls? Actually This is my first project so I never use .htaccess. And how to create url from database and show all related products this is the first task I have to finish.
– Sarah
Nov 15 at 6:09












Possible duplicate of How can I create a dynamic URL in php?
– Thomas Jeriko
Nov 15 at 6:15




Possible duplicate of How can I create a dynamic URL in php?
– Thomas Jeriko
Nov 15 at 6:15












@Thomas Jeriko, exactly like the question you have suggested I am also confused - The thing is, I don't understand how I can pass the $sellerid from the url to the php itself dynamically. Like www.xyz.com/sellerid1
– Sarah
Nov 15 at 6:17




@Thomas Jeriko, exactly like the question you have suggested I am also confused - The thing is, I don't understand how I can pass the $sellerid from the url to the php itself dynamically. Like www.xyz.com/sellerid1
– Sarah
Nov 15 at 6:17




1




1




@Sarah Why don't you use a framework like laravel or codeignitor?
– Jestin Sebastian
Nov 15 at 6:30




@Sarah Why don't you use a framework like laravel or codeignitor?
– Jestin Sebastian
Nov 15 at 6:30












3 Answers
3






active

oldest

votes

















up vote
0
down vote













Do you have sellers table?
if yes, so you can fetch sellers from table and make link dynamically.



query:



SELECT id, name FROM tbl_sellers WHERE enabled=1 LIMIT 10;


html (index.php):



$result = ; // execute $query

// loop on result
foreach($result as $item)
echo "<a href="www.xyz.com/seller.php?id=sellerid{$id}">{$name}</a>";


seller.php:



// Getting request id from url parameters and cast to integer
$sellerId = (int)str_replace('sellerid', '', isset($_REQUEST['id']) ? $_REQUEST['id'] : '');

if(!$sellerId || $sellerId < 1){
exit('Seller not found.');
}


$query = "SELECT * FROM tbl_products WHERE seller_id='{$sellerId}'";
$result = ; // execute $query

// fetch query
exit(var_dump($result));





share|improve this answer























  • @ Ata amini, Thanks for the valuable reply. This concept I know and have mentioned in my question above, I don't want to create urls like www.xyz.com/seller.php?id=sellerid1. I want if someone hit the url like: www.xyz.com/sellerid1 then all the products related to sellerid will show. The thing is, I don't understand how I can pass the $sellerid from the url to the php itself dynamically.
    – Sarah
    Nov 15 at 6:21










  • use this line: $sellerId = (int)str_replace('sellerid', '', isset($_REQUEST['id']) ? $_REQUEST['id'] : '');
    – Ata amini
    Nov 15 at 6:24












  • Getting parameters from url can done with: $_GET, $_REQUEST and $_POST if your request method is post.
    – Ata amini
    Nov 15 at 6:26


















up vote
0
down vote













Using core php here. add the below lines in your .htaccess file. Assuming your default file is index.php here.



RewriteEngine on

RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
RewriteRule ^seller/([^/]+)$ seller.php?sellerid=$1


Now when you will try to open the URL http://www.yoururl.com/seller/{your_dynamic_seller_id_comes_here}. suppose you are opening the URL http://www.yoururl.com/seller/1 then you will get the dynamic seller id from the below code (seller.php).



<?php
$sellerid = $_GET['sellerid'];
//get the result from database query

$dbquery = "SELECT * FROM Products WHERE seller_id='$sellerid' ";
//execute the above query and use the result and do your stuff.

?>


Hope this helps you.






share|improve this answer




























    up vote
    0
    down vote













    Maybe you can use MVC framework like Laravel,Codeigniter, or other framework use MVC.
    MVC Framework , can do, exactly you want, like



    www.xyz.com/sellerid1


    or
    you can do like this but the link not form like



    www.xyz.com/sellerid1


    but like



    www.xyz.com/sellerid/1


    index.php :



    <?php
    //get request url
    $request_uri = explode('/', $_SERVER['REQUEST_URI']);
    // print_r($request_uri);
    if($request_uri[2]=='sellerid'){
    include 'test.php';
    }
    ?>


    test.php :



    <?php  
    echo $request_uri[2].'/'.$request_uri[3];
    ?>


    .htaccess :



    RewriteEngine on
    RewriteCond $1 !^(index.php|resources|robots.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]


    And how to create link is like :



    <?php  
    $url="http://www.example.com/";
    $theproduct=array(...);//Fill with your sellerid
    foreach ($theproduct as $key) {
    ?>
    <a href="<?=$url.'sellerid/'.$key['seller_id']?>"></a>
    <?php
    }
    ?>





    share|improve this answer



















    • 1




      @ Thomas Jeriko, Thanks for the reply. Unfortunately I am not using it. No framework. Without framework is this not possible?
      – Sarah
      Nov 15 at 6:11










    • ah , i see. yes you can do that without framework , see this answer stackoverflow.com/questions/27570522/…
      – Thomas Jeriko
      Nov 15 at 6:13










    • im tested on localhost
      – Thomas Jeriko
      Nov 15 at 6:44










    • here demo gif gph.is/2B77JWJ
      – Thomas Jeriko
      Nov 15 at 6:53










    • @ Thomas Jeriko, Thanks Thomas for a great help. I want to know what if sellerid is: best-book-seller-in-newyork then the url will be www.xyz.com/best-book-seller-in-newyork
      – Sarah
      Nov 15 at 6:57











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313232%2fhow-to-create-clean-url-fetching-data-from-mysql-in-php%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Do you have sellers table?
    if yes, so you can fetch sellers from table and make link dynamically.



    query:



    SELECT id, name FROM tbl_sellers WHERE enabled=1 LIMIT 10;


    html (index.php):



    $result = ; // execute $query

    // loop on result
    foreach($result as $item)
    echo "<a href="www.xyz.com/seller.php?id=sellerid{$id}">{$name}</a>";


    seller.php:



    // Getting request id from url parameters and cast to integer
    $sellerId = (int)str_replace('sellerid', '', isset($_REQUEST['id']) ? $_REQUEST['id'] : '');

    if(!$sellerId || $sellerId < 1){
    exit('Seller not found.');
    }


    $query = "SELECT * FROM tbl_products WHERE seller_id='{$sellerId}'";
    $result = ; // execute $query

    // fetch query
    exit(var_dump($result));





    share|improve this answer























    • @ Ata amini, Thanks for the valuable reply. This concept I know and have mentioned in my question above, I don't want to create urls like www.xyz.com/seller.php?id=sellerid1. I want if someone hit the url like: www.xyz.com/sellerid1 then all the products related to sellerid will show. The thing is, I don't understand how I can pass the $sellerid from the url to the php itself dynamically.
      – Sarah
      Nov 15 at 6:21










    • use this line: $sellerId = (int)str_replace('sellerid', '', isset($_REQUEST['id']) ? $_REQUEST['id'] : '');
      – Ata amini
      Nov 15 at 6:24












    • Getting parameters from url can done with: $_GET, $_REQUEST and $_POST if your request method is post.
      – Ata amini
      Nov 15 at 6:26















    up vote
    0
    down vote













    Do you have sellers table?
    if yes, so you can fetch sellers from table and make link dynamically.



    query:



    SELECT id, name FROM tbl_sellers WHERE enabled=1 LIMIT 10;


    html (index.php):



    $result = ; // execute $query

    // loop on result
    foreach($result as $item)
    echo "<a href="www.xyz.com/seller.php?id=sellerid{$id}">{$name}</a>";


    seller.php:



    // Getting request id from url parameters and cast to integer
    $sellerId = (int)str_replace('sellerid', '', isset($_REQUEST['id']) ? $_REQUEST['id'] : '');

    if(!$sellerId || $sellerId < 1){
    exit('Seller not found.');
    }


    $query = "SELECT * FROM tbl_products WHERE seller_id='{$sellerId}'";
    $result = ; // execute $query

    // fetch query
    exit(var_dump($result));





    share|improve this answer























    • @ Ata amini, Thanks for the valuable reply. This concept I know and have mentioned in my question above, I don't want to create urls like www.xyz.com/seller.php?id=sellerid1. I want if someone hit the url like: www.xyz.com/sellerid1 then all the products related to sellerid will show. The thing is, I don't understand how I can pass the $sellerid from the url to the php itself dynamically.
      – Sarah
      Nov 15 at 6:21










    • use this line: $sellerId = (int)str_replace('sellerid', '', isset($_REQUEST['id']) ? $_REQUEST['id'] : '');
      – Ata amini
      Nov 15 at 6:24












    • Getting parameters from url can done with: $_GET, $_REQUEST and $_POST if your request method is post.
      – Ata amini
      Nov 15 at 6:26













    up vote
    0
    down vote










    up vote
    0
    down vote









    Do you have sellers table?
    if yes, so you can fetch sellers from table and make link dynamically.



    query:



    SELECT id, name FROM tbl_sellers WHERE enabled=1 LIMIT 10;


    html (index.php):



    $result = ; // execute $query

    // loop on result
    foreach($result as $item)
    echo "<a href="www.xyz.com/seller.php?id=sellerid{$id}">{$name}</a>";


    seller.php:



    // Getting request id from url parameters and cast to integer
    $sellerId = (int)str_replace('sellerid', '', isset($_REQUEST['id']) ? $_REQUEST['id'] : '');

    if(!$sellerId || $sellerId < 1){
    exit('Seller not found.');
    }


    $query = "SELECT * FROM tbl_products WHERE seller_id='{$sellerId}'";
    $result = ; // execute $query

    // fetch query
    exit(var_dump($result));





    share|improve this answer














    Do you have sellers table?
    if yes, so you can fetch sellers from table and make link dynamically.



    query:



    SELECT id, name FROM tbl_sellers WHERE enabled=1 LIMIT 10;


    html (index.php):



    $result = ; // execute $query

    // loop on result
    foreach($result as $item)
    echo "<a href="www.xyz.com/seller.php?id=sellerid{$id}">{$name}</a>";


    seller.php:



    // Getting request id from url parameters and cast to integer
    $sellerId = (int)str_replace('sellerid', '', isset($_REQUEST['id']) ? $_REQUEST['id'] : '');

    if(!$sellerId || $sellerId < 1){
    exit('Seller not found.');
    }


    $query = "SELECT * FROM tbl_products WHERE seller_id='{$sellerId}'";
    $result = ; // execute $query

    // fetch query
    exit(var_dump($result));






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 15 at 6:28

























    answered Nov 15 at 6:16









    Ata amini

    13




    13












    • @ Ata amini, Thanks for the valuable reply. This concept I know and have mentioned in my question above, I don't want to create urls like www.xyz.com/seller.php?id=sellerid1. I want if someone hit the url like: www.xyz.com/sellerid1 then all the products related to sellerid will show. The thing is, I don't understand how I can pass the $sellerid from the url to the php itself dynamically.
      – Sarah
      Nov 15 at 6:21










    • use this line: $sellerId = (int)str_replace('sellerid', '', isset($_REQUEST['id']) ? $_REQUEST['id'] : '');
      – Ata amini
      Nov 15 at 6:24












    • Getting parameters from url can done with: $_GET, $_REQUEST and $_POST if your request method is post.
      – Ata amini
      Nov 15 at 6:26


















    • @ Ata amini, Thanks for the valuable reply. This concept I know and have mentioned in my question above, I don't want to create urls like www.xyz.com/seller.php?id=sellerid1. I want if someone hit the url like: www.xyz.com/sellerid1 then all the products related to sellerid will show. The thing is, I don't understand how I can pass the $sellerid from the url to the php itself dynamically.
      – Sarah
      Nov 15 at 6:21










    • use this line: $sellerId = (int)str_replace('sellerid', '', isset($_REQUEST['id']) ? $_REQUEST['id'] : '');
      – Ata amini
      Nov 15 at 6:24












    • Getting parameters from url can done with: $_GET, $_REQUEST and $_POST if your request method is post.
      – Ata amini
      Nov 15 at 6:26
















    @ Ata amini, Thanks for the valuable reply. This concept I know and have mentioned in my question above, I don't want to create urls like www.xyz.com/seller.php?id=sellerid1. I want if someone hit the url like: www.xyz.com/sellerid1 then all the products related to sellerid will show. The thing is, I don't understand how I can pass the $sellerid from the url to the php itself dynamically.
    – Sarah
    Nov 15 at 6:21




    @ Ata amini, Thanks for the valuable reply. This concept I know and have mentioned in my question above, I don't want to create urls like www.xyz.com/seller.php?id=sellerid1. I want if someone hit the url like: www.xyz.com/sellerid1 then all the products related to sellerid will show. The thing is, I don't understand how I can pass the $sellerid from the url to the php itself dynamically.
    – Sarah
    Nov 15 at 6:21












    use this line: $sellerId = (int)str_replace('sellerid', '', isset($_REQUEST['id']) ? $_REQUEST['id'] : '');
    – Ata amini
    Nov 15 at 6:24






    use this line: $sellerId = (int)str_replace('sellerid', '', isset($_REQUEST['id']) ? $_REQUEST['id'] : '');
    – Ata amini
    Nov 15 at 6:24














    Getting parameters from url can done with: $_GET, $_REQUEST and $_POST if your request method is post.
    – Ata amini
    Nov 15 at 6:26




    Getting parameters from url can done with: $_GET, $_REQUEST and $_POST if your request method is post.
    – Ata amini
    Nov 15 at 6:26












    up vote
    0
    down vote













    Using core php here. add the below lines in your .htaccess file. Assuming your default file is index.php here.



    RewriteEngine on

    RewriteCond %(REQUEST_FILENAME) !-f
    RewriteCond %(REQUEST_FILENAME) !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    RewriteRule ^seller/([^/]+)$ seller.php?sellerid=$1


    Now when you will try to open the URL http://www.yoururl.com/seller/{your_dynamic_seller_id_comes_here}. suppose you are opening the URL http://www.yoururl.com/seller/1 then you will get the dynamic seller id from the below code (seller.php).



    <?php
    $sellerid = $_GET['sellerid'];
    //get the result from database query

    $dbquery = "SELECT * FROM Products WHERE seller_id='$sellerid' ";
    //execute the above query and use the result and do your stuff.

    ?>


    Hope this helps you.






    share|improve this answer

























      up vote
      0
      down vote













      Using core php here. add the below lines in your .htaccess file. Assuming your default file is index.php here.



      RewriteEngine on

      RewriteCond %(REQUEST_FILENAME) !-f
      RewriteCond %(REQUEST_FILENAME) !-d
      RewriteRule ^(.*)$ index.php/$1 [L,QSA]
      RewriteRule ^seller/([^/]+)$ seller.php?sellerid=$1


      Now when you will try to open the URL http://www.yoururl.com/seller/{your_dynamic_seller_id_comes_here}. suppose you are opening the URL http://www.yoururl.com/seller/1 then you will get the dynamic seller id from the below code (seller.php).



      <?php
      $sellerid = $_GET['sellerid'];
      //get the result from database query

      $dbquery = "SELECT * FROM Products WHERE seller_id='$sellerid' ";
      //execute the above query and use the result and do your stuff.

      ?>


      Hope this helps you.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Using core php here. add the below lines in your .htaccess file. Assuming your default file is index.php here.



        RewriteEngine on

        RewriteCond %(REQUEST_FILENAME) !-f
        RewriteCond %(REQUEST_FILENAME) !-d
        RewriteRule ^(.*)$ index.php/$1 [L,QSA]
        RewriteRule ^seller/([^/]+)$ seller.php?sellerid=$1


        Now when you will try to open the URL http://www.yoururl.com/seller/{your_dynamic_seller_id_comes_here}. suppose you are opening the URL http://www.yoururl.com/seller/1 then you will get the dynamic seller id from the below code (seller.php).



        <?php
        $sellerid = $_GET['sellerid'];
        //get the result from database query

        $dbquery = "SELECT * FROM Products WHERE seller_id='$sellerid' ";
        //execute the above query and use the result and do your stuff.

        ?>


        Hope this helps you.






        share|improve this answer












        Using core php here. add the below lines in your .htaccess file. Assuming your default file is index.php here.



        RewriteEngine on

        RewriteCond %(REQUEST_FILENAME) !-f
        RewriteCond %(REQUEST_FILENAME) !-d
        RewriteRule ^(.*)$ index.php/$1 [L,QSA]
        RewriteRule ^seller/([^/]+)$ seller.php?sellerid=$1


        Now when you will try to open the URL http://www.yoururl.com/seller/{your_dynamic_seller_id_comes_here}. suppose you are opening the URL http://www.yoururl.com/seller/1 then you will get the dynamic seller id from the below code (seller.php).



        <?php
        $sellerid = $_GET['sellerid'];
        //get the result from database query

        $dbquery = "SELECT * FROM Products WHERE seller_id='$sellerid' ";
        //execute the above query and use the result and do your stuff.

        ?>


        Hope this helps you.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 at 11:30









        Madhur Sharma

        1136




        1136






















            up vote
            0
            down vote













            Maybe you can use MVC framework like Laravel,Codeigniter, or other framework use MVC.
            MVC Framework , can do, exactly you want, like



            www.xyz.com/sellerid1


            or
            you can do like this but the link not form like



            www.xyz.com/sellerid1


            but like



            www.xyz.com/sellerid/1


            index.php :



            <?php
            //get request url
            $request_uri = explode('/', $_SERVER['REQUEST_URI']);
            // print_r($request_uri);
            if($request_uri[2]=='sellerid'){
            include 'test.php';
            }
            ?>


            test.php :



            <?php  
            echo $request_uri[2].'/'.$request_uri[3];
            ?>


            .htaccess :



            RewriteEngine on
            RewriteCond $1 !^(index.php|resources|robots.txt)
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ index.php/$1 [L,QSA]


            And how to create link is like :



            <?php  
            $url="http://www.example.com/";
            $theproduct=array(...);//Fill with your sellerid
            foreach ($theproduct as $key) {
            ?>
            <a href="<?=$url.'sellerid/'.$key['seller_id']?>"></a>
            <?php
            }
            ?>





            share|improve this answer



















            • 1




              @ Thomas Jeriko, Thanks for the reply. Unfortunately I am not using it. No framework. Without framework is this not possible?
              – Sarah
              Nov 15 at 6:11










            • ah , i see. yes you can do that without framework , see this answer stackoverflow.com/questions/27570522/…
              – Thomas Jeriko
              Nov 15 at 6:13










            • im tested on localhost
              – Thomas Jeriko
              Nov 15 at 6:44










            • here demo gif gph.is/2B77JWJ
              – Thomas Jeriko
              Nov 15 at 6:53










            • @ Thomas Jeriko, Thanks Thomas for a great help. I want to know what if sellerid is: best-book-seller-in-newyork then the url will be www.xyz.com/best-book-seller-in-newyork
              – Sarah
              Nov 15 at 6:57















            up vote
            0
            down vote













            Maybe you can use MVC framework like Laravel,Codeigniter, or other framework use MVC.
            MVC Framework , can do, exactly you want, like



            www.xyz.com/sellerid1


            or
            you can do like this but the link not form like



            www.xyz.com/sellerid1


            but like



            www.xyz.com/sellerid/1


            index.php :



            <?php
            //get request url
            $request_uri = explode('/', $_SERVER['REQUEST_URI']);
            // print_r($request_uri);
            if($request_uri[2]=='sellerid'){
            include 'test.php';
            }
            ?>


            test.php :



            <?php  
            echo $request_uri[2].'/'.$request_uri[3];
            ?>


            .htaccess :



            RewriteEngine on
            RewriteCond $1 !^(index.php|resources|robots.txt)
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ index.php/$1 [L,QSA]


            And how to create link is like :



            <?php  
            $url="http://www.example.com/";
            $theproduct=array(...);//Fill with your sellerid
            foreach ($theproduct as $key) {
            ?>
            <a href="<?=$url.'sellerid/'.$key['seller_id']?>"></a>
            <?php
            }
            ?>





            share|improve this answer



















            • 1




              @ Thomas Jeriko, Thanks for the reply. Unfortunately I am not using it. No framework. Without framework is this not possible?
              – Sarah
              Nov 15 at 6:11










            • ah , i see. yes you can do that without framework , see this answer stackoverflow.com/questions/27570522/…
              – Thomas Jeriko
              Nov 15 at 6:13










            • im tested on localhost
              – Thomas Jeriko
              Nov 15 at 6:44










            • here demo gif gph.is/2B77JWJ
              – Thomas Jeriko
              Nov 15 at 6:53










            • @ Thomas Jeriko, Thanks Thomas for a great help. I want to know what if sellerid is: best-book-seller-in-newyork then the url will be www.xyz.com/best-book-seller-in-newyork
              – Sarah
              Nov 15 at 6:57













            up vote
            0
            down vote










            up vote
            0
            down vote









            Maybe you can use MVC framework like Laravel,Codeigniter, or other framework use MVC.
            MVC Framework , can do, exactly you want, like



            www.xyz.com/sellerid1


            or
            you can do like this but the link not form like



            www.xyz.com/sellerid1


            but like



            www.xyz.com/sellerid/1


            index.php :



            <?php
            //get request url
            $request_uri = explode('/', $_SERVER['REQUEST_URI']);
            // print_r($request_uri);
            if($request_uri[2]=='sellerid'){
            include 'test.php';
            }
            ?>


            test.php :



            <?php  
            echo $request_uri[2].'/'.$request_uri[3];
            ?>


            .htaccess :



            RewriteEngine on
            RewriteCond $1 !^(index.php|resources|robots.txt)
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ index.php/$1 [L,QSA]


            And how to create link is like :



            <?php  
            $url="http://www.example.com/";
            $theproduct=array(...);//Fill with your sellerid
            foreach ($theproduct as $key) {
            ?>
            <a href="<?=$url.'sellerid/'.$key['seller_id']?>"></a>
            <?php
            }
            ?>





            share|improve this answer














            Maybe you can use MVC framework like Laravel,Codeigniter, or other framework use MVC.
            MVC Framework , can do, exactly you want, like



            www.xyz.com/sellerid1


            or
            you can do like this but the link not form like



            www.xyz.com/sellerid1


            but like



            www.xyz.com/sellerid/1


            index.php :



            <?php
            //get request url
            $request_uri = explode('/', $_SERVER['REQUEST_URI']);
            // print_r($request_uri);
            if($request_uri[2]=='sellerid'){
            include 'test.php';
            }
            ?>


            test.php :



            <?php  
            echo $request_uri[2].'/'.$request_uri[3];
            ?>


            .htaccess :



            RewriteEngine on
            RewriteCond $1 !^(index.php|resources|robots.txt)
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ index.php/$1 [L,QSA]


            And how to create link is like :



            <?php  
            $url="http://www.example.com/";
            $theproduct=array(...);//Fill with your sellerid
            foreach ($theproduct as $key) {
            ?>
            <a href="<?=$url.'sellerid/'.$key['seller_id']?>"></a>
            <?php
            }
            ?>






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 16 at 7:48

























            answered Nov 15 at 6:09









            Thomas Jeriko

            448




            448








            • 1




              @ Thomas Jeriko, Thanks for the reply. Unfortunately I am not using it. No framework. Without framework is this not possible?
              – Sarah
              Nov 15 at 6:11










            • ah , i see. yes you can do that without framework , see this answer stackoverflow.com/questions/27570522/…
              – Thomas Jeriko
              Nov 15 at 6:13










            • im tested on localhost
              – Thomas Jeriko
              Nov 15 at 6:44










            • here demo gif gph.is/2B77JWJ
              – Thomas Jeriko
              Nov 15 at 6:53










            • @ Thomas Jeriko, Thanks Thomas for a great help. I want to know what if sellerid is: best-book-seller-in-newyork then the url will be www.xyz.com/best-book-seller-in-newyork
              – Sarah
              Nov 15 at 6:57














            • 1




              @ Thomas Jeriko, Thanks for the reply. Unfortunately I am not using it. No framework. Without framework is this not possible?
              – Sarah
              Nov 15 at 6:11










            • ah , i see. yes you can do that without framework , see this answer stackoverflow.com/questions/27570522/…
              – Thomas Jeriko
              Nov 15 at 6:13










            • im tested on localhost
              – Thomas Jeriko
              Nov 15 at 6:44










            • here demo gif gph.is/2B77JWJ
              – Thomas Jeriko
              Nov 15 at 6:53










            • @ Thomas Jeriko, Thanks Thomas for a great help. I want to know what if sellerid is: best-book-seller-in-newyork then the url will be www.xyz.com/best-book-seller-in-newyork
              – Sarah
              Nov 15 at 6:57








            1




            1




            @ Thomas Jeriko, Thanks for the reply. Unfortunately I am not using it. No framework. Without framework is this not possible?
            – Sarah
            Nov 15 at 6:11




            @ Thomas Jeriko, Thanks for the reply. Unfortunately I am not using it. No framework. Without framework is this not possible?
            – Sarah
            Nov 15 at 6:11












            ah , i see. yes you can do that without framework , see this answer stackoverflow.com/questions/27570522/…
            – Thomas Jeriko
            Nov 15 at 6:13




            ah , i see. yes you can do that without framework , see this answer stackoverflow.com/questions/27570522/…
            – Thomas Jeriko
            Nov 15 at 6:13












            im tested on localhost
            – Thomas Jeriko
            Nov 15 at 6:44




            im tested on localhost
            – Thomas Jeriko
            Nov 15 at 6:44












            here demo gif gph.is/2B77JWJ
            – Thomas Jeriko
            Nov 15 at 6:53




            here demo gif gph.is/2B77JWJ
            – Thomas Jeriko
            Nov 15 at 6:53












            @ Thomas Jeriko, Thanks Thomas for a great help. I want to know what if sellerid is: best-book-seller-in-newyork then the url will be www.xyz.com/best-book-seller-in-newyork
            – Sarah
            Nov 15 at 6:57




            @ Thomas Jeriko, Thanks Thomas for a great help. I want to know what if sellerid is: best-book-seller-in-newyork then the url will be www.xyz.com/best-book-seller-in-newyork
            – Sarah
            Nov 15 at 6:57


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313232%2fhow-to-create-clean-url-fetching-data-from-mysql-in-php%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

            ComboBox Display Member on multiple fields

            Is it possible to collect Nectar points via Trainline?