selectable table rows in php

Posted on 2005-04-15
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.
Question by:boody
    1 Comment
    LVL 32

    Accepted Solution

    There are several options

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


    <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
    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="">

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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now