RCS Posted April 15, 2008 Share Posted April 15, 2008 I always see sites that have php linking like index.php?1 or index.php?about Can someone tell me how you would do this instead of using something like index.php or about.php Thanks in advance. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted April 15, 2008 Share Posted April 15, 2008 not sure what you're asking. Anything after the ? will be in the $_GET array. do a print_r on it to see the keys and values. Quote Link to comment Share on other sites More sharing options...
discomatt Posted April 15, 2008 Share Posted April 15, 2008 Try this out: <?php echo '<a href="'. $_SERVER['SCRIPT_NAME'] .'?page=info">Info</a><br />'; echo '<a href="'. $_SERVER['SCRIPT_NAME'] .'?page=about">About</a><br />'; echo '<a href="'. $_SERVER['SCRIPT_NAME'] .'?page=contact">Contact</a><br />'; echo '<br /><br />'; if ($_GET['page'] == 'info') { echo 'This is the info page'; } elseif ($_GET['page'] == 'about') { echo 'This is the about page'; } elseif ($_GET['page'] == 'contact') { echo 'This is the contact page'; } else { echo 'No page has been picked yet'; } ?> Should get you on the right track Quote Link to comment Share on other sites More sharing options...
RCS Posted April 15, 2008 Author Share Posted April 15, 2008 Say you have these links on your site home, about, sales catalog, gallery but you don't want to display your link pages like home.php, about.php, sales_catalog.php, gallery.php or e.g http:www.yoursite.com/home.php but oyu want to display it like http:www.yoursite.com/index.php?home or http:www.yoursite.com/index.php?1 Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted April 15, 2008 Share Posted April 15, 2008 See discomatt's post above. I think that most of the time when you see those you are looking at someone using an MVC framework who just hasn't utilized mod_rewrite to clean up the url. I use, and recommend, Zend Framework. http://framework.zend.com Quote Link to comment Share on other sites More sharing options...
RCS Posted April 15, 2008 Author Share Posted April 15, 2008 I posted that after thanks for the help. Quote Link to comment Share on other sites More sharing options...
poleposters Posted April 15, 2008 Share Posted April 15, 2008 You create those links yourself just as you would an ordinary HTML link. I found the idea a little confusing at first also. But its really quite simple. Say for example you have a list of users on your site. You want to display the user names, age, and a link to their profile. You'd do this. You'd have a page that displays the list.Perhaps you'd retrieve records only of users who are 24 years old. Your table structure has the columns, userid,name,age $query="SELECT * FROM table WHERE age=24";<!--Select all the records where the age=24--> $result=mysql_query($query);<!--Execute the query--> $number=mysql_num_rows($result)<!--Check how many results are returned--> if($number>0)<!--Make sure more than 0 results are returned before the next line is executed--> { while($list=mysql_fetch_array($result)<!--Place the result into an array and run a loop through the results--> { print "<h1>$list[username]</h1}" <!--Print the user name--> print "<h2>$list[age]</h2}" <!--Print the user age--> print "<a href='viewprofile.php?userid=$list[userid]'>View user profile</a><!--Print the profile link--> So basically what you have done is selected all the data from the table where the age =24, placed it into an array and printed the array. The important part is that you have printed a link with ?userid=xyz attached to the end of it. All this does is carry a GET value. You can then test for this value on the link page. So <a href='viewprofile.php?userid=594'> Links to a page called viewprofile.php On the viewprofile.php page you can start with some code to retireve the value that has been passed. $userid=$_GET['userid] This will store the value 594 in the variable $userid. You can use this value to perfomr queries to display the user profile e.g SELECT profile_picture FROM table WHERE userid=$userid etc. Quote Link to comment Share on other sites More sharing options...
RCS Posted April 15, 2008 Author Share Posted April 15, 2008 Thank you very much for taking the time to explain. Quote Link to comment 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.