Jump to content

Recommended Posts

This may not have a PHP answer but looking for guidance here.

 

This is part one of a 2 stage process.

I have a table generated from an SQL query. I use the following to display the contents.

<?php while($row_events = mysqli_fetch_array($result_events)):;?>
    <tr>
    <td><?php echo $row_events['Dat'];?></td>
    <td><?php echo $row_events['EventName'];?></td>   
    <td style="display:none;"><?php echo $row_events['EventID'];?>                 
    </tr>
<?php endwhile;?>

I would like the EventID to be displayed (or something similar just to confirm it is working) when I hover over the corresponding table line.

 

Part two will be to transfer to a new HTML page with the EventID used as a key with an OnClick event.

Edited by CB150Special
Link to comment
https://forums.phpfreaks.com/topic/304384-display-content-of-table-row-with-hover/
Share on other sites

  1. <?php while($row_events = mysqli_fetch_array($result_events)):;?>

  2. <tr data-popup="<?php echo $row_events['EventID'];?>">

...

</tr>

<?php endwhile;?>

 

Look for some jQuery or JavaScript library to show it, or right your own.

 

You should do the following:

  1. Learn about PDO!

Separate your database scope and your page display scope.  Consider using a template engine such as twig/smarty.

Alternately is there another way to display a table and execute a link to another html page with some parameter of the table passed with that selection choice.

 

An example would be a list of students and clicking on a student brings up their exam results.

I'm not sure I understand your reply.

<a href="link/to/exam_results.php?param_1=value_1&param_2=value_2"><!-- student list entry --></a>

Whether I use param_1=value_1 or a session variable is a matter of choice, the question is how do I get the parameter from the row I select on the table into that variable.

Forget about variables, onclick events and whatnot.

 

This is the definition of a plain old link: You click on something, and then the browser takes you to another page. In your case, you click on an entry in a list of events, and then you're taken to the event page (with the ID in the URL).

In the mean time

  <td onclick="alert(<?php $row_events['EventID'];?>)"><?php echo $row_events['EventName'];?></td>                     

works but below does not. I get the on event message but no EventID

    <td onclick=disp_event()><?php echo $row_events['EventName'];?></td>   
     ....

    <script>
        function disp_event() {
            alert(<?php echo $row_events['EventID'];?>)
        }
    </script> 

<!DOCTYPE html>
<html>
<head>
<title>An HTML standard template</title>
<meta charset="utf-8">
<style>
.records {
border-collapse: collapse;
}
.records td {
border: 1px solid black;
padding: 0;
}
.records a {
display: block;
padding: 15px;
}
</style>
</head>
<body>
<table class="records">
<tr>
<td><a href="http://example.com?row=1">Click anywhere in the cell</a></td>
<td><a href="http://example.com?row=1">Click anywhere in the cell</a></td>
</tr>
<tr>
<td><a href="http://example.com?row=2">Click anywhere in the cell</a></td>
<td><a href="http://example.com?row=2">Click anywhere in the cell</a></td>
</tr>
</table>
</body>
</html>
  • Like 1

Not so simple. I've tried all the options except the right one !!

   <td><a href='mem_event.php?eventID = 71'> ><?php echo $row_events['Dat'];?></td>
   $sql_event = 'SELECT * FROM fees WHERE EventID = "'.$_GET['eventID'].'" ORDER BY MemName';

I get Undefined Index eventID

 

How do I list all the variables so I can see exactly what I have  ?

This is the third and last time I'm explaining this: Use – prepared – statements. As long as you don't take care of basic code sanity, it's pointless to talk about errors, because errors are to be expected.

 

If you simply inspect your parameters with var_dump(), you'll also see that you don't have an eventID parameter. Your parameter is called “eventID ” with a space after the name and within the value.

Your parameter is called “eventID ” with a space after the name and within the value.

I have no idea what you are talking about ?

 

Is there something like var_dump() that list all the variables on a form, or can you see them with Inspect Element on a web page ?

I have no idea what you are talking about ?

 

Look:

mem_event.php?eventID = 71
                     ^^^

You have a parameter with the name “eventID<space>” (PHP turns that into “eventD_”) and the value “<space>71”. If you don't want that, remove the spaces.

 

 

 

Is there something like var_dump() that list all the variables on a form, or can you see them with Inspect Element on a web page ?

 

Well, URL parameters are in the URL bar. And POST parameters can be seen in the HTTP request in the Network tab.

 

What's more important, though, is how the parameters actually look like in PHP, hence var_dump().

This is the only page I could find on <a href> with parameter passing if anyone is interested.

 

http://html.net/tutorials/php/lesson10.php

 

Can I get something like this to work ?

<a href='test.php?eventID='.<?php$row_events['EventID'];?> >

Let's turn that into

<a href="<?= html_escape('events.php?'.http_build_query(['id' => $event['event_id']]), 'UTF-8') ?>">Link text</a>
/**
 * HTML-escapes a string, so that it can safely be included in simple HTML contexts
 *
 * @param string $raw_input the string which should be escaped
 * @param string $encoding  the character encoding of the input string
 *
 * @return string the encoded string
 */
function html_escape($raw_input, $encoding)
{
    return htmlspecialchars($raw_input, ENT_QUOTES | ENT_SUBSTITUTE, $encoding);
}
  • The http_build_query() function takes care of turning a set of parameters into a syntactically valid URL query
  • HTML-escaping makes sure the URL can be inserted into an HTML context without breaking anything
  • Following standard naming conventions (e. g. snake_case instead of CamelCase) avoids confusion and interoperability trouble
  • Like 1
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.