Advertisement

09.03.2008 at 09:12AM PDT, ID: 23699766
[x]
Attachment Details

Showing Category Name in the url with .htaccess

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.1
Tags:

PHP, Apache

Hi, I have a script that use .htaccess url rewrite in order to show bettter url.
It is a classified ads script. In the home page, you have a list of category. Their url looks like:

http://www.mysite.com/categorie/2

where 2 is the Category ID.

Now, I would like this url to become:

http://www.mysite.com/cars/2

with the category name istead of the word "categorie", if I click on the cars link (of course!).


This is the actual rewrite rule:
RewriteRule ^categorie/([0-9]+)$ ads.php?c=$1 [L]

This is the php code in the page that prints out the categories list:

$q1 = "select * from class_categories order by CategoryName";
$r1 = mysql_query($q1) or die(mysql_error());

while($a1 = mysql_fetch_array($r1))
{
      $MyID[] = $a1['CategoryID'];
      $MyName[] = $a1['CategoryName'];

      $q2 = "select count(*) from class_catalog where CategoryID = '".$a1['CategoryID']."'";
      $r2 = mysql_query($q2) or die(mysql_error());
      $a2 = mysql_fetch_array($r2);

      $MyNumber[] = $a2[0];
}


if(!empty($MyID))
{
      for($i = '0'; $i <= (count($MyID)); $i+=2)
      {
            $one = $i;
            $two = $i + 1;


            $categories .= "<tr>\n\t\t";
      
            if(!empty($MyID[$one]))
            {
                  $categories .= "<td width=\"265\"><a href=\"categorie/$MyID[$one]\" title=\"Ads $MyName[$one]\" class=\"BlueLinka\">$MyName[$one]</a></td>\n\t\t";
            }
            else
            {
                  $categories .= "<td width=\"265\">&nbsp;</td>\n\t\t";
            }

            if(!empty($MyID[$two]))
            {
                  $categories .= "<td width=\"265\"><a href=\"categorie/$MyID[$two]\" title=\"Ads $MyName[$two]\" class=\"BlueLinka\">$MyName[$two]</a></td>\n\t\t</tr>\n\t\t";
            }
            else
            {
                  $categories .= "<td width=\"265\">&nbsp;</td>\n\t\t</tr>\n\t\t";
            }

}
}


Does anybody help me?


Answered By: WyTyz
Expert Since: 11/07/2003
Accepted Solutions: 13
Computer Expertise: Intermediate
Education: RUG Groningennull, Master's Degree
WyTyz has been an Expert for 5 years 2 months, during which he has posted 45 comments and answered 13 questions. WyTyz is just one of 2167 experts in the MySQL Server Zone. 1 expert collaborated on this answer, which was graded an "A" by the asker.
 
 
 
 
20081119-EE-VQP-48 / EE_QW_2_20070628