点击更新变量 [英] Update a variable on click

查看:231
本文介绍了点击更新变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我写了以下内容,但我想知道将$ message_id =添加到单击以查看收件箱消息的$ row [’id’]的最佳方法是什么。如果我只是将$ message_id =静态设置为39,然后单击$ row ['id']为39的行,则会打开该消息。

basically I've written the following but I'm wondering what the best way to get $message_id = to the $row['id'] you click on to view an inbox message. If I just statically set $message_id = to say 39 and click on the row that's $row['id'] is 39 it'll open the message.

基本上它确实列出了我拥有的收件箱邮件,并使用行ID对其进行锚定,以便在标头中使用以显示该邮件的全部内容。

Basically what it does is list inbox messages I have, and anchor tag them with its row id to be used in the header to show the full contents of that message.

<p>
    <?php
    $message_id = "39";

    if (isset($_GET[$message_id]) && empty($_GET[$message_id])) {
        $username = $user_data['username'];

        $get_message = mysql_query("SELECT * FROM `users_inbox` WHERE `id` = '$message_id' AND `send_to` = '$username'");
        $get_message_result = mysql_fetch_array($get_message);

        echo '<h1><u>' . $get_message_result['subject'] . '</u></h1>';
        echo $get_message_result['sent_from'] . '<br />';
        echo $get_message_result['body'] . '<br />';
        echo '<a href="inbox.php">Back</a>';
    } 

    $username = $user_data['username'];
    $result = mysql_query("SELECT * FROM `users_inbox` WHERE `send_to` = '$username'"); 
    ?>

    <table border="1">
        <tr>
            <td>From</td>
            <td>Subject</td>
            <td>Date</td>
        </tr>
            <?php
            while($row = mysql_fetch_array($result))
            {
                echo
                '<tr>' .
                '<td><a href="#">' . $row['sent_from'] . '</a></td>' .
                '<td><a href="?' . $row['id'] . '">' . $row['subject'] . '</a></td>' .
                '<td>' . $row['post_date'] . '</td>' .
                '</tr>';
            }
            ?>
    </table>
</p>

任何人都知道这是否可能,因为我知道代码是从上至下读取的我知道您根本无法返回。

Anyone know if this is even possible, as I know code is read from top to bottom and as far as I'm aware you cant go back upwards at all.

推荐答案

我认为 $ user_data ['username'] 已设置或可用,如果是,则可以传递您选择的变量名,该变量名指向消息ID,而不是仅发送ID(例如:我将其设置为 msg_id ),现在您可以通过 $ _ GET ['msg_id']

I assume that the $user_data['username'] is set or available,if yes then you could pass a variable name of you choice which points the message id instead of sending only the id (eg: i am setting it as msg_id ), Now you can access the message id via $_GET['msg_id']

<p>
<?php
$username = $user_data['username'];
if ( isset( $_GET['msg_id'] ) ) {     

    $get_message = mysql_query("SELECT * FROM `users_inbox` WHERE `id` = '$message_id' AND `send_to` = '$username'");
    $get_message_result = mysql_fetch_array($get_message);

    echo '<h1><u>' . $get_message_result['subject'] . '</u></h1>';
    echo $get_message_result['sent_from'] . '<br />';
    echo $get_message_result['body'] . '<br />';
    echo '<a href="inbox.php">Back</a>';
}else{
  $result = mysql_query("SELECT * FROM `users_inbox` WHERE `send_to` = '$username'"); 

?>


<table border="1">
        <tr>
            <td>From</td>
            <td>Subject</td>
            <td>Date</td>
        </tr>
            <?php
            while($row = mysql_fetch_array($result))
            {
                echo
                '<tr>' .
                '<td><a href="#">' . $row['sent_from'] . '</a></td>' .
                '<td><a href="inbox.php?msg_id=' . $row['id'] . '">' . $row['subject'] . '</a></td>' .
                '<td>' . $row['post_date'] . '</td>' .
                '</tr>';
            }
            ?>
    </table>
</p>

这篇关于点击更新变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆