ghqwerty Posted October 3, 2008 Share Posted October 3, 2008 ok so i know how pagination works but how can i program a page e.g a users profile so that the url would say something like blahblahblah/stats.php/user=blah so that they could just reference there page any help greatly appreciated Link to comment https://forums.phpfreaks.com/topic/126912-solved-unique-reference-to-a-page/ Share on other sites More sharing options...
F1Fan Posted October 3, 2008 Share Posted October 3, 2008 blahblahblah/stats.php?user=blah Then var $_REQUEST['user'] = "blah" Link to comment https://forums.phpfreaks.com/topic/126912-solved-unique-reference-to-a-page/#findComment-656439 Share on other sites More sharing options...
ghqwerty Posted October 3, 2008 Author Share Posted October 3, 2008 huh Link to comment https://forums.phpfreaks.com/topic/126912-solved-unique-reference-to-a-page/#findComment-656464 Share on other sites More sharing options...
F1Fan Posted October 3, 2008 Share Posted October 3, 2008 OK, let's say you have stats.php and you want to pass a variable into it: Let's say you direct a user to blahblahblah/stats.php?user=blah because their username is "blah." stats.php <?php if (!isset($_REQUEST['user'])) die("No user!"); $username = $_REQUEST['user']; echo "User name is $username!"; ?> Then, going to blahblahblah/stats.php?user=blah would display: User name is blah! That help? Link to comment https://forums.phpfreaks.com/topic/126912-solved-unique-reference-to-a-page/#findComment-656466 Share on other sites More sharing options...
ghqwerty Posted October 3, 2008 Author Share Posted October 3, 2008 so if the users name was matty where would i assign this ??? thanks for the other help Link to comment https://forums.phpfreaks.com/topic/126912-solved-unique-reference-to-a-page/#findComment-656468 Share on other sites More sharing options...
F1Fan Posted October 3, 2008 Share Posted October 3, 2008 What do you mean "where would I assign this?" You would give them a link, like: <a href="blahblahblah/stats.php?user=<?php echo $username; ?>">View your stats page!</a> Is that what you mean? Link to comment https://forums.phpfreaks.com/topic/126912-solved-unique-reference-to-a-page/#findComment-656471 Share on other sites More sharing options...
ghqwerty Posted October 3, 2008 Author Share Posted October 3, 2008 ok i kinda get it once ive finished refurbishing my stats page ill try it out .. then ill come back if i have a problem thanks for the help Link to comment https://forums.phpfreaks.com/topic/126912-solved-unique-reference-to-a-page/#findComment-656473 Share on other sites More sharing options...
ghqwerty Posted October 3, 2008 Author Share Posted October 3, 2008 ok just tried it a bit im going to do it with user id's instead of name for less errors im getting confused please go through it again in REALY dumb talk lol as in where to put it also where you have $_REQUEST['user'] what should the user bit be replaced with ?? Link to comment https://forums.phpfreaks.com/topic/126912-solved-unique-reference-to-a-page/#findComment-656561 Share on other sites More sharing options...
F1Fan Posted October 3, 2008 Share Posted October 3, 2008 OK, if you have a page's URL, let's say http://example.com/somepage.php, you can pass variables into it by listing them after a ? and separating them with a &. So, let's say you want to pass one variable in called "somevar1" and you want it to equal "blah." After the http://example.com/somepage.php just add a ? and somevar1=blah, and you get http://example.com/somepage.php?somevar1=blah. If you wanted to pass the same "somevar1" and a new one, maybe "anothervar1" and make it equal "anotherblah," you would do this: http://example.com/somepage.php?somevar1=blah&anothervar1=anotherblah. Each variable passed in after the ? will be added to the $_REQUEST array. So, $_REQUEST['somevar1'] will give you a value of "blah" and $_REQUEST['anothervar1'] will equal "anotherblah." To test this, create a page on your site called "test.php" and put ONLY this inside it: <?php print_r($_REQUEST); ?> Now, navigate to that page and add variables to the URL string and you should see the results. Try something like: http://<yoursite>.com/test.php?somevar1=blah&anothervar1=anotherblah Link to comment https://forums.phpfreaks.com/topic/126912-solved-unique-reference-to-a-page/#findComment-656579 Share on other sites More sharing options...
ghqwerty Posted October 3, 2008 Author Share Posted October 3, 2008 Array ( [user] => hello [phpSESSID] => 0d015c1ac8d00d8144c4c372dfc65c10 ) thats what i get so how would i factor that into a stats page would i have to do the query based on the variable up top?? how would i do that man i feel like ive gone 10 spaces backwards in php i used to grasp it well easily and now i feel like im just starting again what i want to do is do localhost/stats.php?uid=$usersid so would i get that $userid from the session i create when i log in ?? also where i have the query to get the stats would i have to do $who = "select * from members where id = ' " . $_request['uid'] . " ' "; ???i think im getting it Link to comment https://forums.phpfreaks.com/topic/126912-solved-unique-reference-to-a-page/#findComment-656588 Share on other sites More sharing options...
F1Fan Posted October 3, 2008 Share Posted October 3, 2008 Not sure what you're asking for. If you have the userid in a session variable, why do you need to pass it into another page?!? To retrieve your uid variable that you've passed with localhost/stats.php?uid=$usersid, you'll need to reference the $_REQUEST['uid'] variable. Link to comment https://forums.phpfreaks.com/topic/126912-solved-unique-reference-to-a-page/#findComment-656592 Share on other sites More sharing options...
ghqwerty Posted October 3, 2008 Author Share Posted October 3, 2008 ok so i want it so when the user clicks on stats they see their own stats but if they click on someone elses name in the users list then they get taken to their profile with their stats and their custom profile Link to comment https://forums.phpfreaks.com/topic/126912-solved-unique-reference-to-a-page/#findComment-656593 Share on other sites More sharing options...
Flames Posted October 3, 2008 Share Posted October 3, 2008 i dont think you need a code to check for that. i think your looking for a code to check if its your username so you can edit it and stuff if it is your page? all you need is something similar to. <?php $queryposts = "SELECT posts FROM table WHERE id = '$_REQUEST['uid']" $posts = mysql_query($queryposts); echo "Posts: " . $posts; ?> Link to comment https://forums.phpfreaks.com/topic/126912-solved-unique-reference-to-a-page/#findComment-656596 Share on other sites More sharing options...
F1Fan Posted October 3, 2008 Share Posted October 3, 2008 OK, so for each of your links, let's say your code is this: <?php $query = "SELECT username, uid FROM users..."; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)){ echo "<a href='users.php?uid={$row['uid']}'>{$row['username']}</a><br>"; } ?> Then, users.php: <?php $uid = $_REQUEST['uid']; $query = "SELECT * FROM users WHERE uid = '$uid'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); print_r($row); ?> Link to comment https://forums.phpfreaks.com/topic/126912-solved-unique-reference-to-a-page/#findComment-656603 Share on other sites More sharing options...
ghqwerty Posted October 3, 2008 Author Share Posted October 3, 2008 haha i did it on my own kinda understand it once i get used to it ill be a pro at it thanks Link to comment https://forums.phpfreaks.com/topic/126912-solved-unique-reference-to-a-page/#findComment-656611 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.