homepage Welcome to WebmasterWorld Guest from 54.198.130.203
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
show html file in a portion of the webpage + change URL (with & and =)
peter_10




msg:4603796
 10:18 am on Aug 21, 2013 (gmt 0)

Hello,

I want to have a webpage with multiple portions (created through tables).

When somebody clicks on a link from menu, the html file belonging to that link/section, should appear in a portion of the webpage, and the URL needs to be changed ( like www.yourwebpage.com/index.php?id=2&id=7 ).

As I have heard, this is possible only with PHP, because the server needs to be queried to show such content in a portion of webpage.
And also, the link can be bookmarked (with use of GET) and accessed afterwards at the desired time.
Do I need that each link from menu be a form that would have GET method?

Can anyone give me a short and simple example of such a PHP script that would lead to this result?
Or is there any more simple language other than PHP for this result?

Thank you in advance!
Peter

 

lucy24




msg:4603803
 11:06 am on Aug 21, 2013 (gmt 0)

There exist languages other than php, but they're not any easier. If any of your content is dynamic-- "created through tables" as you put it-- it has to be done in some language. It can't be static html. Unless, er, you want to code several hundred html pages to cover all possible permutations of requests ;)

Any URL can be bookmarked, including parameters (the part after the ? question mark).

But wait!

Since you're doing all this from scratch, now is also the time to work out what you want your URLs to look like. They don't have to have the conventional boring form

www.example.com/index.php?id=2&page=7

just because those are the parameters. You definitely don't need or want "index.php" in there. But beyond that, you can go to something like

www.example.com/widget2/foobar7

and then behind the scenes you rewrite according to a pattern, like

widget(\d+)/foobar(\d+) >> /index.php?id=$1&page=$7

(Note that you cannot have two different parameters with the same name. I don't know if the duplicate "id=" in your post was a typo.)

Once you've figured out exactly what you want to do, you can then start working out the php. You can't simply copy and paste some generic code. But it isn't hard to get started-- especially since a lot of the page can be perfectly normal, static html. I don't generally approve of the "If I can do it, anyone can" argument. But honestly, if I can make php pages, 98% of the people reading WebmasterWorld forums can do it :)


Then there's Option B, which is to shop around for an existing CMS that will do what you need. Then you don't have to learn anything.

JD_Toims




msg:4604573
 1:35 am on Aug 24, 2013 (gmt 0)

If I'm understanding correctly, it sounds like you're saying you would like to have people click a link and the content on some portion of the page change without changing the actual page they're viewing?

If that's the case, you'll likely need to use a combination of JavaScript [something along the lines of <a href=javascript:void(function('value_to_send'));>Click Here to Show Info</a> + pushState() within the function() to change the URL and add a fragment identifier + an AJAX request to get the info and change the display]. You can then use PHP to receive the value sent by JS and return the result for the specific info.

To get a visitor back to the same display from a link or bookmark you'll need to check for a hash + the info it contains with JS [location.hash] at the time the page loads and "fire" the same [or similar] function to load/display the correct information at the time a visitor lands.

Note: There's usually 10 different ways to code everything, especially when combining JS and PHP, but this was the first one that came to my mind.

Readie




msg:4604648
 11:27 am on Aug 24, 2013 (gmt 0)

If JD_Toim's assumption that you would like part of the page to change, without reloading the page, then for your desire to have the URL change, you will need to use the HTML5 history API.

[diveintohtml5.info...]

... I believe this is how Sound Cloud do their really cool "continue playing during navigation" thing.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved