Jump to content

Recommended Posts

Hello,

I have created a webpage that essentially generates an sql query and then puts the results into a table that is displayed.
On one of the columns in this displayed table, I want to allow the user to click on each of the values which will in turn execute a php function. I have the hyperlink working but this is to a separate page.
What I actually need to do is firstly - just ran a php function that will create a new table beneath the currently displayed one.
Secondly, once this is achieved, I need to pass some value to the function so that the generated table is dependent on the value that was clicked.

I've tried a few things and researched but I am struggling. I am a beginner.

Any help would be greatly appreciated.

Here is an extract of the code used for inputting data into the original table - showValuesSR is the function name
<?php
while (!$rsMetrics->EOF) {
?>
<tr>
<?php
for ($x=0; $x<$numberOfFields; $x++) {

if ($fieldNames[$x] == "Values_SR"){ ?>
<td><a href= ?showValuesSR><?php echo $rsMetrics->fields[$fieldNames[$x]]->Value?></a></td>
<?php }
else{ ?>
<td><?php echo $rsMetrics->fields[$fieldNames[$x]]->Value?></td>
<?php
}
}
?>
</tr>
<?php
$rsMetrics->MoveNext();
}

?>

</table>

<?php
function showValuesSR(){

?>
<table border="0" cellpadding="5" width="100%">
<tr><td
background="../images/table_toolbar_bkg.gif" align="center"><font color="Blue" face="verdana" size="2"><strong>function working</strong></td></tr>
</table>

<?php
}
?>

Link to comment
https://forums.phpfreaks.com/topic/291095-href-to-php-function/
Share on other sites

Mouse clicks are handled by the browser on the client after PHP has finished executing on the server so you cannot call a PHP function directly in response to a mouse event. If you don't want to go to another page then you need to use AJAX.

 

You should Google AJAX to find out more but, basically, you use a javascript function to send a request message to a PHP script the server in response to the click. The script executes and sends data back to the calling function which then displays it on the page.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.