Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7583063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:35:31+00:00 2026-05-30T18:35:31+00:00

I have two table posts & categories post_id | post_title | post_content | post_cat

  • 0

I have two table posts & categories

post_id | post_title  | post_content   | post_cat
--------------------------------------------------
1         Hello World  welcome to my..   1
.         ..           ..                ..

categories table

cat_id | cat_name | cat_parent
-----------------------------
1        News       NULL
2        Sports     1
.        ...        .. 

Let’s say current category link for news is http://domain.com/category/1/

MySQL statment

SELECT posts.post_id,
       posts.post_id,
       posts.post_title,
       posts.post_content,
       posts.post_cat,
       categories.cat_id,
       categories.cat_name,
       categories.cat_parent
FROM   posts
       INNER JOIN categories
         ON posts.post_cat = categories.cat_id  
       WHERE posts.post_cat = (int)$_GET['cat_id']

So we can get a result for post_cat = 1

According to my current database structure, how do I remove the ID but change it to be a nice slug? Example :-

Main category - http://domain.com/category/news/
Sub category  - http://domain.com/category/news/sports/

Let me know a clue how script will tell News is equal 1 on post_cat column?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:35:32+00:00Added an answer on May 30, 2026 at 6:35 pm

    You can use an .htaccess file to rewrite the URL’s for you.

    The entry in the .htaccess file would look something like this :

    RewriteEngine on
    RewriteCond $1 ^category 
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ parseCategoryUrl.php?q=$1 [L,QSA]
    

    I’ll break down the lines here to help understand whats going on and what each line means :

    1. Turn the RewriteEngine on.
    2. This rewrite will only occur on URL’s where the first word after the host name is category – all URL’s starting with that word will be processed by the lines below.
    3. The rule will exclude URL’s that point to actual files !-f
    4. The rule will exclude URL’s that point to actual directories !-d
    5. The actual rule will capture the entire request_uri and pass it to the parseCategoryUrl.php file with the entire request as a parameter called q (query) in the $_GET array. The flags at the end of the rule (L,QSA) do two things.
      • L – This is the last rule. After processing this line the .htaccess file will stop performing actions on the current URL.
      • QSA – Append the query string to the rewritten URL (so that we can parse it later).

    Your parseCategoryUrl.php file could contain something similar to the following :

    $request = explode('/',$_GET['q'] );
    array_shift($request);
    

    The first line will split the request by slashes into an array – and the second line removes the word category from the beginning of the array (because we know that we are parsing a category URL).

    The final $request array, with a URL example such as :
    http://example.domain.com/category/news/sports
    Will be this :

    Array
    (
        [0] => news
        [1] => sports
    )
    

    So you see here that you have now successfully split the URL into an array; All you have to do now is query your database and and provide the user with the correct page.
    Because the parseCategoryUrl.php page in fact has no output, you could just use an include() function to insert the correct page according to the URL that was provided.


    SEO is about making your pages and their URL’s more informative to search engines so that a user searching the internet will be able to receive page results that are related to their search query. A search engine looking at the URL :
    http://domain.com/category/1/2
    will not be able to extract much information. However if your URL contains (as your question requires), category information, then a search engine will be able to deduct that the specific URL is related to :

    • http://domain.com/category/news/ – news
    • http://domain.com/category/news/sports – sports news
    • http://domain.com/category/blog/ – blog
    • etc…
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables Posts and comments Post Table Post_id Post_content Comments table comment_id
Okay so I have two tables, a category table and a posts table. I
I have two tables. One table contains comments on posts, another contains commenter information
I have two items, users and posts, and a join table linking them together.
I have two table like this table_CN (_id, name, phone, favorite, title) table_EN (_id,
I have two table emptable1(empid,status) emptable2(empid,week) i want to select all the empid whose
I have two tables: Table 1: ID, PersonCode, Name, Table 2: ID, Table1ID, Location,
Say I have a database called Poll and have these two table structures. poll
I have two tables: a source table and a target table. The target table
I have two fields in a table. One contains values such as BTA, BEA,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.