简体   繁体   中英

Passing a table value to another page for SQL query

This is my first post here, so go easy on me!

I'm developing a portion of a website that stores problems that arise during business operations, basically a part of CRM. I have everything set where the user can update queries and search for specific ID numbers. The problem I'm having is when I search the DB for ID numbers with a certain account number. I can get a list of them all in table form, but what I want is for the user to be able to click on the ID number and then update it on the update page. What is happening is that only the last row queried is being sent to the update page no matter which ID number is clicked.

Here is my code on the Find page that displays the table:

$querystr = $wpdb->prepare( "SELECT * FROM wp_prs WHERE prsAcct = %s ORDER BY prsID", $account );
$query_results = $wpdb->get_results( $querystr, ARRAY_N );

if ( !isset ($_POST['submit-prs'])) {

// I've left out all css and html that is here

<form action="update.php" method="post">
<?php
$arraySize = count($query_results);
for ( $i = 0; $i < $arraySize; $i++ ) {
    for ( $j = 0; $j < 10; $j++ ) {
        if ( $j == 0 ) {
            $prs_number = $query_results[$i][0];
?>
            <tr>
            <input type="hidden" name="prs-number" value="<?php esc_html_e($prs_number); ?>" />
            <td><input type="submit" name="submit-prs-find" value="<?php esc_html_e($prs_number); ?>" /></td>

<?php
        } else if ( $j == 2 ) {
            $new_date = newDate($query_results[$i][$j]);
            echo '<td>' . $new_date . '</td>';
        } else if ( $j == 5 ) {
            echo '<td id="subject-font">' . $query_results[$i][$j] . '</td>';
        } else if ( ($j >= 6) && ($j <= 9) ) {
            echo '<td>' . substr( $query_results[$i][$j], 0, 20 ) . '...' . '</td>';

        } else {
            echo '<td>' . $query_results[$i][$j] . '</td>';
        }
    }
    echo '</tr>';
}
?>
</form>

I've tried using $_SESSION but still to no avail. Every time I only post the last row ID. Any help would be awesome, I've been stuck on this for a while now and I've exhausted all google searches I can think of.

Thanks in advance!

You have a Submit for each record, but the <form> is not closed for each one, but surrounding them all.

Try including the <form> </form> within the loop.

You will get loads of submit buttons but maybe that is what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM