?
Solved

selectable table rows in php

Posted on 2005-04-15
1
Medium Priority
?
666 Views
Last Modified: 2013-12-12
I've been asked to make selectable table rows for any dynamic HTML tables that are created.  Is there a way to simulate the behavior of  a regular submit button by only using rows?  Obviously once a user selects a record, the new page will display data that corresponds to the selected record-so I would need to find a way to capture that data when the new php page is generating.
0
Comment
Question by:boody
1 Comment
 
LVL 32

Accepted Solution

by:
Batalf earned 750 total points
ID: 13794294
There are several options

1) Direct links from a row
2) Popuplate a hidden field and post a form.

Example:

<script type="text/javascript">
function redirect(id){
    document.forms[0].theID.value = id; // setting theID field of the form
    document.forms[0].submit(); // Submit form
}
</script>
<?
echo "<table>";
$res = mysql_query("select id,theName from myTable");
while($inf = mysql_fetch_array($res)){  // Listing out items in the table
    echo "<tr>";
    echo "<td><a href=\"#\" onclick=\"redirect(".$inf["id"]."');return false\">".$inf["theName"]."</td>";
    echo "</tr>\n";
}
echo "</table>";
?>
<form action="page2.php" method="post">
<input type="hidden" name="theID" value="">
</form>
</body>
</html>

Then pick up $_POST['theID'] in the "page2.php" file.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question