skip to Main Content

I want to echo some text based on the page id in the url, for example if the page is 72 i want to output “mens”

products_new.php?categories_id=72

i dont know where to start but im guessing im looking to write some php that says something like: if : products_new.php?categories_id=72 then echo ‘Mens’

any ideas, im using oscommerce?

4

Answers


  1. That’s part of the querystring, you can just check $_GET['categories_id'], not the whole path.

    Login or Signup to reply.
  2. Values sent through the url are available in the $_GET superglobal array:

    $id = $_GET['categories_id'];
    
    if ($id == 72)
    {
        echo "Mens";
    }
    
    Login or Signup to reply.
  3. Once you get the category id from the query string (as in Cyclone’s answer) you will probably pick up the value “Mens” not from a conditional statement but from a database table or a PHP array in memory that maps the category ids to their descriptions.

    Don’t use an if statement for this, especially if you have a lot of categories!

    Login or Signup to reply.
  4. You can use $_GET['categories_id'] to get that page id, which can then be displayed.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search