mikey3521 Posted June 17, 2007 Share Posted June 17, 2007 Hello, I've started to code a community site. I'm aware there are loads out there, but unless I do it all myself theres to much code to-go through to find out what it does.. so I'm starting one from scratch. Right now I have a database table called "Users" each user has an "ID" & "username" www.mysitename.com/index.php?users.mainpage=1 or www.mysitename.com/?users.mainpage=1 works and brings you to that users main page. '1' represents the users ID number.. so that would load user '1'. I want to make mod_rewrite allow me to also put in the users name... so the username Mike is linked to ID 1. so www.mysitename.com/?users.mainpage=mike would goto www.mysitename.com/?users.mainpage=1 now I am to understand I have to use a sitemap, or external php script (I want to use php) I just can't for the life of me figure out exactly how or what i need to-do. I've done a fair amount of searching but nothing. So if any has any tutorials or links suggestions or simply knows how and can make me a sample that would be awesome. I can also be found on IRC / msn with the following info: msn = morrisf89@hotmail.com irc = irc.freenode.net in channel #__mike Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/55894-solved-php-retrive-mysql-data-htaccess-mod_rewrite/ Share on other sites More sharing options...
The Little Guy Posted June 17, 2007 Share Posted June 17, 2007 Options +FollowSymlinks RewriteEngine on RewriteRule ^(.*)/$ user.php?name=$1 [nc] Assuming you only have unique usernames, you could do this <?php if(isset($_GET['name'])){ $sql = mysql_query("SELECT * FROM users WHERE userName='{$_GET['name']}'")or die(mysql_error()); }elseif(isset($_GET['id'])){ $sql = mysql_query("SELECT * FROM users WHERE id='{$_GET['id']}'")or die(mysql_error()); }else{ $error = TRUE; } if(!$error){ $row = mysql_fetch_array($sql); echo 'Viewing '.$row['user'].'\'s profile'; }else{ echo 'Invalid user'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/55894-solved-php-retrive-mysql-data-htaccess-mod_rewrite/#findComment-276121 Share on other sites More sharing options...
mikey3521 Posted June 17, 2007 Author Share Posted June 17, 2007 awesome thank you so much, editied it and it worked great!! just 2 more quick questions... I've edited it so www.mysite.com/mike/ will goto www.mysite.com/index.php?users.mainpage=1 via your mod rewrite & php script. Now my first question is www.mysite.com/mike/ works... www.mysite.com/mike dosn't... ?? how come? and secondly. once a user gets redirected is there anywhere to keep the address in the bar the same? so when they get sent to www.mysite.com/index.php?users.mainpage=1 it stays as www.mysite.com/mike/ Thanks agaiN! Quote Link to comment https://forums.phpfreaks.com/topic/55894-solved-php-retrive-mysql-data-htaccess-mod_rewrite/#findComment-276147 Share on other sites More sharing options...
The Little Guy Posted June 17, 2007 Share Posted June 17, 2007 in the mod rewrite, try this: RewriteRule ^http://mysite.com/(.*)$ user.php?name=$1 [nc] The answer is because of the trailing slash before the first dollar sign. Quote Link to comment https://forums.phpfreaks.com/topic/55894-solved-php-retrive-mysql-data-htaccess-mod_rewrite/#findComment-276166 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.