Page 1 of 1

OnClick - PHP Event...

Posted: Fri Aug 03, 2007 3:52 pm
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...

Posted: Fri Aug 03, 2007 4:12 pm
by RobertGonzalez
PHP = Server side.

onClick = Client side.

They are not going to talk to each other without a post of some sort.

Posted: Fri Aug 03, 2007 4:22 pm
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.

Posted: Fri Aug 03, 2007 4:52 pm
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>';
}
?>