Forum Moderators: coopster

Message Too Old, No Replies

Select from database and change to id?

         

askeli

2:20 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



Hi

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

jatar_k

11:37 pm on Aug 25, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



in the other code we fixed try

echo $catid;

right before the if ($catid) { and see what is output when you are trying widgetgreen/large

you may also want to try a catname with a space as well then and see if that works.

askeli

8:43 am on Aug 26, 2004 (gmt 0)

10+ Year Member



ill try that this evening, with cat names with spaces it works fine by adding the underscore

Thanks

askeli

9:54 pm on Aug 26, 2004 (gmt 0)

10+ Year Member



tried it,

it prints:

widgetgreen

4

it still prints the same if i go to url widgetgreen/large

thanks

jatar_k

3:23 am on Aug 27, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



problem is more likely the rewrite stripping the slash then

any way you can use something different instead of a slash in the names?

Timotheos

5:04 pm on Aug 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe I'm not understanding but... seems to me you need to extend your rewrite to account for another variable like $subcat.

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;
}

askeli

6:21 pm on Aug 27, 2004 (gmt 0)

10+ Year Member



i dont know how to make it create sub catergories without the slash? i dont know where it creates the slash before adding to database etc

askeli

9:14 pm on Aug 27, 2004 (gmt 0)

10+ Year Member



sorted it!

Thanks for all your help, i changed the / to a -

jatar_k

9:18 pm on Aug 27, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



all sorted then?

nicely done askeli

askeli

9:59 pm on Aug 27, 2004 (gmt 0)

10+ Year Member



all sorted for now.

Thanks to your help Jatar_K im learning a lot

Cheers

This 39 message thread spans 2 pages: 39