Query Strings, how do you do it? |
Query Strings, how do you do it? |
![]()
Post
#1
|
|
![]() Mel Blanc was allergic to carrots. ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 6,371 Joined: Aug 2008 Member No: 676,291 ![]() |
I was wondering how you could make those url's that have a question mark and a few equal signs and such at the end of a url. I belive they are called query strings, right? How can I do it to like make a page go to a next page such as this where it has "?page=2". I know it has to something with PHP and I tried googling tutorials but I just don't understand. Can someone please explain how to do this like if I wanted to make the page go the second page using a simple HTML "a" tag? Thanks.
![]() |
|
|
![]() |
![]()
Post
#2
|
|
![]() Offline. ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 609 Joined: Mar 2007 Member No: 507,591 ![]() |
I know the code above is too advance for someone who is a beginner but here is a simply code. The code is mostly self explanatory.
CODE <?php if ( isset( $_GET['page'] ) ){ $page = $_GET['page']; # Getting page ID ex. ?page=2 } if ( empty( $page ) || $page == '' || $page == '0' ){ echo "Home Page Content"; } else if ( $page == '1' ){ echo "Page 1 Content Goes Here"; } else if ( $page == '2' ){ echo "Page 2 Content Goes Here"; } else { echo "Page Not Found"; } ?> Within the code their are for pages: - Homepage - Page 1 - Page 2 - Error Page To access the Homepage you simply can access it by going to the page.php, or page.php?page=0 To access page one and to you can go to page.php?page=1 or page.php?page=2 To acess the error page you can go to any page that is not listed ex. 3, 4, 5, etc. To add new page you can add an CODE else if( $page == 'PAGEID') { echo "Page content goes here"; } Make sure it is places before the else statement. PAGEID Doesn't have to be a number it can be letters too. HERE is a preview |
|
|
![]() ![]() |