Forum Moderators: coopster
I am having a bit of trouble here trying to go to a name in a Mysql database and retrieve its id, what i am actually trying to do is:
convert a url with for example dir/index.php?action=showcat&idcat=4
to
dir/tablename/ instead of dir/4/ (4 being a table id)
so what i need is to change the name in the url back to the id, i have tried the following without luck.
if ($catid){
$db=mysql_connect("localhost","user","password");
mysql_select_db("database",$db);
$query="SELECT 'id' FROM dir_categories WHERE name= '.$catid.' ";
$result=mysql_query($query);
$record=mysql_fetch_assoc($result);
$idcat=$record["id"];
}
i have setup the rewrite successfully in htaccess
(thanks to this website) to rewrite as "catid"
I am just trying to use the table names instead of id's for SE purposes, as /widgetgreen/ is better than /4/
Basically is what im trying possible? or am i wasting my time trying
I hope somebody understands what im on about as i seem to of confused myself.
Many Thanks
dir/widgetgreen/large
dir/index.php?idcat=widgetgreen&subcat=large
Now you can do what you want with both variables and even put them back together with the slash.
$new = $idcat
if(isset($subcat)) {
$new .= "/" . $subcat;
}