dqwn64004 2012-08-10 23:46
浏览 35

从所选的id填充行的值

I'm using PHP to populate names into an option list based on values from a database. Once a name is selected I want to populate the values of a row based on whatever name has been selected.

I had no problem populating the option list with the name values, but once I select a name the records of that row will not display in the input boxes.

Here is the code I'm working with:

$query = "SELECT name, id 
FROM artists 
ORDER BY name";

$mysql_stuff = mysql_query($query, $mysql_link);
while($row = mysql_fetch_row($mysql_stuff)) {

 $artists_name = htmlspecialchars(stripslashes($row[0]));
 $artists_id = stripslashes($row[1]);

    // we compare the id of the record returned and the one we have selected
    if ($artists_id) { 
        $selected = $artists_id;
    } else {
        $selected = "";
    }
    print("<option value=\"$artists_id\">$artists_name</option>
    ");
}

print("</select>
<input type=\"Submit\" name=\"submit\" value=\"Update\">
<input type=\"Submit\" name=\"delete\" value=\"Delete\">

<br >
<br />
Edit Biography:
</td>
</tr>
");

if (isset($_POST['submit'])) {
    print("<tr valign=\"top\">
    <td valign=\"top\" width=\"150\">Name</td>
    <td valign=\"top\">Artist Biography</td>
    </tr>

    ");


    print("<tr valign=\"top\" bgcolor=\"$colour\">
    <td valign=\"top\">
    <input type=\"text\" name=\"artists_name[$selected]\" value=\"$artists_name\" size=\"40\" />
    </td>

    <td valign=\"top\">
    <textarea name=\"artists_Biography[$selected]\"  cols=\"40\" rows=\"10\">$artists_Biography</textarea>
    </td>


    </tr>
    ");

}   


print("</table>
</form>
");

Can I please get some assistance with populating the values of the selected name into the input boxes.

  • 写回答

2条回答 默认 最新

  • douling0053 2012-08-11 00:03
    关注

    So your submitting artist ID to the post. The post would then refresh or change the page. Assuming the action is that page you have the ID in your post. How do you get Artist Name from the ID? Do you run another sql query on the id to find the name? Might need some clarification on the order of your code to help. Thanks

    评论

报告相同问题?

悬赏问题

  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题