1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how i execute php code in a part of page without reloading the whole page

Discussion in 'PHP' started by MrSearcher, Jun 3, 2010.

  1. #1
    hello there,
    I am wondering how to execute a php code in part of the page without reloading the whole page?
     
    MrSearcher, Jun 3, 2010 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    digitalpoint, Jun 3, 2010 IP
  3. trevHCS

    trevHCS Peon

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The simple answer is you can't as PHP does it's stuff before the output to the browser occurs. Once that's done the user is presented with the HTML code to build the page and never knows that PHP had anything to do with it.

    The only way to update stuff after the page has loaded is to investigate AJAX which uses Javascript to make so called async calls back to the server. It can look a little daunting, but there's loads of tutorials out there for the basics and the Javascript forum on here should be handy too. Just remember that since it's Javascript, search engines can't see it.

    Trev

    Edit: What he said....forgot to hit submit. :)
     
    trevHCS, Jun 3, 2010 IP
  4. georgu

    georgu Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    There are also lots of javascript libraries that could make this task much easier like jQuery or Prototype. They have great AJAX support and also simplifies DOM manipulation.
     
    georgu, Jun 3, 2010 IP
  5. w47w47

    w47w47 Peon

    Messages:
    255
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    with only PHP you can't. but you can use javascript or ajax.
     
    w47w47, Jun 3, 2010 IP
  6. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #6
    Yeah Ajax is the only way i know!
     
    roopajyothi, Jun 4, 2010 IP
  7. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #7
    iframe can do! but is ugly :)
     
    gapz101, Jun 4, 2010 IP
  8. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #8
    Oops! Right but its not mostly used since it displays a scroll bar and makes ugly as you said when page i too long!
    Also there are others like Flash, Flex, Java, SVG and Ruby on Rails etc.,
     
    roopajyothi, Jun 6, 2010 IP
  9. qrpike

    qrpike Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    PHP is a server side language that must be compiled at the server, before any HTML is sent to the browser.

    To do what you are looking to do required JQuery. It is very simple and easy to do and I use it on a lot of my scripts at www.scripteen.com

    You need to include the JQuery source file in the head of your document and then use the following code:

     
    qrpike, Jun 6, 2010 IP