OnClick - PHP Event...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Grandpa0594
Forum Newbie
Posts: 2
Joined: Fri Aug 03, 2007 3:40 pm

OnClick - PHP Event...

Post by Grandpa0594 »

This may be a simple question but I'm stuck on it. I want the user to click on a button(s) such as "A", "B", etc. and call a PHP Function to clear a section of the page and display only items from a database that begin with that letter. I have no problems with the PHP code that selects the information. What I'm stuck on is the syntax of the OnClick event that calls the PHP function ("Refresh"), and what is required in PHP to clear the data already displayed in one section of the page so that new data can be shown. Thank you in advance for any help you may provide...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

PHP = Server side.

onClick = Client side.

They are not going to talk to each other without a post of some sort.
smudge
Forum Contributor
Posts: 151
Joined: Sun May 20, 2007 12:13 pm

Post by smudge »

What you should try to do is link the letters individually to the php script which outputs the new info, like <a href='letter.php?letter=a'>A</a>.
If you feel up to it, maybe using ajax to communicate to make it smoother, since only the data portion of the page is changing.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Try this and see if you can spot what is happening...

Code: Select all

<?php
$thisFile = basename(__FILE__);

if (isset($_GET['testSection']) && $_GET['testSection'] == 'fatBoy') {
    echo '<p>I am showing this section because there was something passed in the query string that matched what I thought it would.</p>';
    echo '<p>Wanna go back to boring? <a href="' . $thisFile . '">Click Here...</a></p>';
} else {
    echo '<p>Wanna see something cool? <a href="' . $thisFile . '?testSection=fatBoy">Click Here...</a></p>';
}
?>
Post Reply