0

在我的页面中,当用户登录到他的帐户时,有两个字段名称和项目,因此每当他登录时,他的姓名填写的名称字段和他的所有项目都列在项目字段的下拉列表中。我的问题是当我编辑此记录时它显示我是他在提交时选择的名称和项目,但我希望在编辑时将他的所有项目列在提交时间。

这是我的提交时间下拉项目代码:

<tr>
           <td>Select Project</td>
           <td>
           <select id="project" name="project">
           <option value="">-- select --</option>
           <?php while($row = mysql_fetch_array($result))
              {
                 $pm = $row['assignpm'];
                 $assignpm = explode(",",$pm);
                 if(in_array($_SESSION['id'], $assignpm)){ ?>

               <option value="<?php echo htmlspecialchars($row['projectname']);?>"><?php echo htmlspecialchars($row['projectname']); ?></option>
 <?php } }?> 
             </select></td>
         </tr>

这是我编辑项目字段的代码:

<tr>
           <td>Select Project</td>
           <td><select name="project" id="project" style="width:145px">
               <option>Select</option>
              <option selected="selected" value="<?php echo $fetuser1['project'];?>"><?php echo $fetuser1['project'];?></option>       
                 </select></td>
         </tr>
4

2 回答 2

0

depends... what do your query look like? one query? two querys? one on the userid, name and stuff and another on the projects...

or are all project in the same table as the fetched username? and how are thy stored (blob, json, simple list)?

And last: mixing php inline with html is a very bad habbit ;)

say you have two querys

//query SELECT projectname FROM whatevertable WHERE userid = 'users-id'

$options = "<option value="">-- select --</option>".PHP_EOL;
while($row = mysql_fetch_array($result))
{
    if(htmlspecialchars($row['projectname']) == $_SESSION['preselected']) //whatever
        $options. = "<option selected="selected" value=".htmlspecialchars($row['projectname']).">".htmlspecialchars($row['projectname'])."</option>".PHP_EOL;
    else
        $options. = "<option value=".htmlspecialchars($row['projectname']).">".htmlspecialchars($row['projectname'])."</option>".PHP_EOL;
}

and after all the php code you can

echo "<td>Select Project</td>
<td>
    <select id=/"project/" name=/"project/">
        {$options}
    </select>
</td>";

But without knowing any of your code but that little php-mixed-html it's hard to answer precisely

于 2013-02-05T13:02:30.977 回答
0

因此,在编辑时,您必须执行与“提交时间”相同的操作。

<tr>
    <td>Select Project</td>
    <td>
        <select name="project" id="project" style="width:145px">
            <option>Select</option>
            <?php 
                while($row = mysql_fetch_array($result)) {
                    $pm = $row['assignpm'];
                    $assignpm = explode(",",$pm);
                    if(in_array($_SESSION['id'], $assignpm)) {
                ?>
                <option 
                    <?php if($fetchuser1['project'] == $row['projectname']) echo "selected='selected'";?> 
                    value="<?php echo htmlspecialchars($row['projectname']);?>"
                >
                    <?php echo htmlspecialchars($row['projectname']); ?>
                </option>
            <?php } }?>
        </select>
    </td>
 </tr>
于 2013-02-05T12:50:51.273 回答