Re: New PHP User with a simple question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Jan 25, 2009 at 02:40:08AM -0500, Christopher W wrote:

> Mr. Kubler,
> 
> Thank you for the help.  I have to admit, I am still in over my head, I
> think.  Perhaps I should just stick to static pages...
> 
> Anyway what I was attempting to do, in the full picture, was be able to just
> switch the text in the text area without actually changing pages.  For
> example, if the user clicks "About Us" (from the home page)the page doesn't
> change, just the text (in the area I designated for text).
> 
> Since I have never used php before (but have read some online and in books)
> what I was trying was:
> 
> if ($page == "home") {echo $home_text;}
> elseif ($page == "about") {echo $about_text;}
> ...
> else {echo $error_text;}
> 
> My problem is that I can't figure out how to get the link-click to assign
> the value to the variable.  I didn't try any php for that end because I
> really didn't know where to begin.  Perhaps I am just going about this the
> wrong way but from the extremely little I have learned about php, I thought
> that I could do it this way easily.
> 
> Thanks for the replies and the help.  I truly appreciate it.
> 

In case this has yet to be answered to your satisfaction...

Your page will *have* to reload when the user presses the button, but
the majority of content can look the same, except for the content you
want to change.

Let's say you've named the button "section" and its value is "home" as
in: 

<input type="text" name="section" value="home"/>

When the user presses the button, the form now shows the value of
"section" as "home". PHP knows this has occurred. So you can make any
action occur by simply (in PHP):

if ($_POST['section'] == 'home') {
    do_something();
}

In your case, you want a section of your HTML page to display something
else. So, wherever you want that content to be displayed in your HTML
page, do this:

<?php
if ($_POST['section'] == 'home') {
    echo "a bunch of text for home stuff";
}
?>

The "<?php" thingie tells Apache to interpret the next part as PHP, and
the "?>" part tells Apache that the PHP part is over. If you're using
GET instead of POST for the form then change "$_POST" above to "$_GET".
Every item in a form yields a POST or GET variable which PHP can read,
just as it did above.

There are alternate ways to do this, but the above is probably the
simplest for you.

I recommend "Programming PHP" an O'Reilly book as a reference for the
language.

Paul


-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux