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 8029241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:22:42+00:00 2026-06-05T00:22:42+00:00

I have an index page that links to a page called categories.php In categories.php,

  • 0

I have an index page that links to a page called categories.php In categories.php, each different category for a forum site has a unique url based on its id (cat_id). However, i want to change this url to be based on its name (cat_name). However, when I do this, I receive the error “The category could not be displayed, please try again later.Unknown column ‘thenameofacategory’ in ‘where clause'”. Is this due to the fact that cat_id is the primary key? How do I replace the

       <a href="category.php?id=' . $row['cat_id'] . '">

with cat_name so that i dont receive errors on the category.php page?

an excerpt from index.php (the important part):

        echo '<tr>';
            echo '<td class="leftpart">';
                echo '<h3><a href="category.php?id=' .                        $row['cat_id'] . '">' . $row['cat_name'] . '</a></h3>' . $row['cat_description'];
            echo '</td>';
            echo '<td class="rightpart">';

            //fetch last topic for each cat
                $topicsql = "SELECT
                                topic_id,
                                topic_subject,
                                topic_date,
                                topic_cat
                            FROM
                                topics
                            WHERE
                                topic_cat = " .  $row['cat_id'] . "
                            ORDER BY
                                topic_date
                            DESC
                            LIMIT
                                1";

                $topicsresult = mysql_query($topicsql);

                if(!$topicsresult)
                {
                    echo 'Last topic could not be displayed.';
                }
                else
                {
                    if(mysql_num_rows($topicsresult) == 0)
                    {
                        echo 'no topics';
                    }
                    else
                    {
                        while($topicrow = mysql_fetch_assoc($topicsresult))
                        echo '<a href="topic.php?id=' . $topicrow['topic_id'] . '">' . $topicrow['topic_subject'] . '</a> at ' . date('d-m-Y', strtotime($topicrow['topic_date']));
                    }
                }
            echo '</td>';
        echo '</tr>';
    }

and here is the page category.php:

      <?php
      //category.php
      include 'connect.php';


      //first select the category based on $_GET['cat_id']
      $sql = "SELECT
        cat_name,
        cat_id,
        cat_description
    FROM
        categories
    WHERE
        cat_id = " . mysql_real_escape_string($_GET['id']);

      $result = mysql_query($sql);

      if(!$result)
      {
echo 'The category could not be displayed, please try again later.' .                     mysql_error();
      }
      else
      {
  if(mysql_num_rows($result) == 0)
  {
    echo 'This category does not exist.';
  }
  else
  {
    //display category data
    while($row = mysql_fetch_assoc($result))
    {
        echo '<h2>Topics in &prime;' . $row['cat_name'] . '&prime;           category</h2><br />';
    }

    //do a query for the topics
    $sql = "SELECT  
                topic_id,
                topic_subject,
                topic_date,
                topic_cat
            FROM
                topics
            WHERE
                topic_cat = " .           mysql_real_escape_string($_GET['id']);

    $result = mysql_query($sql);

    if(!$result)
    {
        echo 'The topics could not be displayed, please try again later.';
    }
    else
    {
        if(mysql_num_rows($result) == 0)
        {
            echo 'There are no topics in this category yet.';
        }
        else
        {
            //prepare the table
            echo '<table border="1">
                  <tr>
                    <th>Topic</th>
                    <th>Created at</th>
                  </tr>';   

            while($row = mysql_fetch_assoc($result))
            {               
                echo '<tr>';
                    echo '<td class="leftpart">';
                        echo '<h3><a href="topic.php?id=' .           $row['topic_id'] . '">' . $row['topic_subject'] . '</a><br /><h3>';
                    echo '</td>';
                    echo '<td class="rightpart">';
                        echo date('d-m-Y',           strtotime($row['topic_date']));
                    echo '</td>';
                echo '</tr>';
            }
        }
    }
}
    }

    ?>

Is it from the fact that cat_id is the primary key that i cant use cat_name as the url and row in the WHERE clause?

Thanks!

  • 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-06-05T00:22:43+00:00Added an answer on June 5, 2026 at 12:22 am

    In categories.php, change

    WHERE cat_id = " . mysql_real_escape_string($_GET['id']);

    to

    WHERE cat_name = '" . mysql_real_escape_string($_GET['id']) ."'";

    The problem was that, in the first line of code, cat_id may be an integer but cat_name is a string. When you did cat_id = $_GET['id'] it was trying to do cat_id = somecatname and not cat_id = 'somecatname'

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that I use on index.php page and I would like
I have a page index.php where i have a link called add_users.php. In add_users.php,
I have a PHP script (index.php) that changes the page shown depending on the
I have an index.html.erb page timesheet that has various js and jquery tables and
I have an index page index.php , and when the user clicks on a
I have an index page with three links as follws. When I click the
I have my index.php page and just afrer my header i want to include
I have the following scenario. I have a index.php page with the following JQuery
I have noticed the following with my page thePage.php. My page thePage.php has a
Let's say I have an index.js.erb file that gets called remotely. How would I

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.