简体   繁体   English

将表值传递到另一个页面以进行SQL查询

[英]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. 我正在开发网站的一部分,用于存储在业务运营过程中出现的问题,基本上是CRM的一部分。 I have everything set where the user can update queries and search for specific ID numbers. 我已设置了所有内容,用户可以在其中更新查询并搜索特定的ID号。 The problem I'm having is when I search the DB for ID numbers with a certain account number. 我遇到的问题是当我在数据库中搜索具有特定帐号的ID号时。 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. 我可以以表格形式获得所有这些列表,但是我想要的是用户能够单击ID号,然后在更新页面上对其进行更新。 What is happening is that only the last row queried is being sent to the update page no matter which ID number is clicked. 发生的情况是,无论单击哪个ID号,只有查询的最后一行都被发送到更新页。

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. 我试过使用$ _SESSION,但仍然无济于事。 Every time I only post the last row ID. 每次我只发布最后一行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. 任何帮助都将是非常棒的,我已经坚持了一段时间,并且用尽了所有我能想到的Google搜索。

Thanks in advance! 提前致谢!

You have a Submit for each record, but the <form> is not closed for each one, but surrounding them all. 您为每条记录都有一个Submit,但是对于每个记录, <form>都不是封闭的,而是围绕它们的。

Try including the <form> </form> within the loop. 尝试在循环中包含<form> </form>

You will get loads of submit buttons but maybe that is what you want. 您将获得大量的提交按钮,但也许就是您想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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