开发者

Reply to a message

I have the following code:

<select name="to" class="combo"  value='
            <?php 
            if(isset($_POST['reply'])) 
            { 
                echo "<option value='$reply'>$reply</option>";
            }
            ?>
            ' />
            <?php

            $q = $database->selectAllUsersNotMe();
            while($row=mysql_fetch_assoc($q))
            {
                $u=$row['username'];
                echo "<option value=\"$u\">$u</option>";
            }
            ?>
            </select>

What this does is produce a combo box with a dropdown for all users on my site excluding the user sending the message.

I am trying to add a reply element to the message. W开发者_运维问答hen i click reply, i use the following code:

                <? $reply = $_POST['rfrom']; ?>


        <form name='reply' method='post' action='/newmessage.php'>
        <input type='hidden' name='rfrom' value='<?php echo $pm->messages[0]['from']; ?>' />
        <input type='hidden' name='rsubject' value='Re: <?php echo $pm->messages[0]['title']; ?>' />
        <input type='hidden' name='rmessage' value='[quote]<?php echo $pm->messages[0]['message']; ?>[/quote]' />
        <input type='submit' name='reply' value='Reply' />
    </form>

The values are correct and definately pass the information using POST.

On the initial piece of code I provided, how can I alter this so the username that I am replying to is selected when I am replying, if not, the usernames are just listed. Thanks


$fromname=(isset($_POST['rfrom'])) ? $_POST['rfrom'] : ''; //ought to validate $_POST
while($row=mysql_fetch_assoc($q)) { 
  $u=$row['username']; 
  $selected=($u==$fromname) ? 'selected="selected"' : '';
  echo "<option value=\"$u\" $selected>$u</option>"; 
}


$replyUser = $_POST['rfrom'];
while($row = mysql_fetch_object($q))
{
if($row->username == $replyUser)
{
echo('<option value="'.$row->username.'" selected="selected">'.$row->username.'</option>');
}else{
echo('<option value="'.$row->username.'">'.$row->username.'</option>');
}
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜