我想知道是否有人能夠幫助我。文本字段中的回聲字段值
通過我之前從本網站收到的一些指導,我已經能夠將腳本放在一起,下面列出了日期信息和相關的單選按鈕,允許選擇每個記錄。
<?php
mysql_connect("hostname", "username", "password")or
die(mysql_error());
mysql_select_db("database");
?>
<html><head>
<title>Location</title>
<style type="text/css">
<!--
.style3 {
font-size: 18px;
font-family: Calibri;
}
-->
</style>
</head>
<form name="addimages">
<p>
<label>
<div align="center" class="style3"> Location Name <br>
<br>
<input name="locationname" type="text" value="<?php echo $locationname;?>" id="locationname" size="80">
</div>
</label>
</p>
<p> </p>
<p>
<?php
$result = mysql_query("SELECT userdetails.userid, finds.dateoftrip, finds.userid, finds.locationid, detectinglocations.locationid, detectinglocations.locationname, finds.findname, finds.finddescription FROM userdetails, finds, detectinglocations WHERE finds.userid=userdetails.userid AND finds.locationid=detectinglocations.locationid AND finds.userid = 1 ORDER BY dateoftrip DESC");
if (mysql_num_rows($result) == 0)
// table is empty
echo 'There are currently no finds recorded for this location.';
else
{
while (list($userid, $dateoftrip, $locationname) =
mysql_fetch_row($result))
{
echo"<table>\n";
echo"<tr>\n"
.
"<td><input type='radio' name='radio' dateoftrip value='{$userid}' /></td>\n"
."<td><small>{$dateoftrip}</small><td>\n"
."</tr>\n";
}
echo"<tr><td colspan=\"3\">";
echo"<br>";
echo"</td></tr>";
echo'</table>';
}
?>
</p>
</form>
我現在試圖做的是將'locationname'值添加到適當的文本字段。
我已將value="<?php echo $locationname;?>"
添加到文本字段,但它仍爲空白。
我認爲問題就出在這裏:
while (list($userid, $dateoftrip, $locationname) = mysql_fetch_row($result))
我用得到的日期列表中的信息,而通常我會用這樣的:
while ($row = mysql_fetch_array($result)) { $locationname = $row['locationname'];
獲取的文本字段的值。
有人可能告訴我,請問是否有一種方法可以將兩條語句合併爲一個我需要的信息,即包含日期列表的表格,同時將'locationname'值'回顯'到文本域。
非常感謝
更新的代碼
<?php
mysql_connect("hostname", "username", "password")or
die(mysql_error());
mysql_select_db("database");
$locationname='';
$result = mysql_query("SELECT userdetails.userid, finds.dateoftrip, finds.userid, finds.locationid, detectinglocations.locationid, detectinglocations.locationname, finds.findname, finds.finddescription FROM userdetails, finds, detectinglocations WHERE finds.userid=userdetails.userid AND finds.locationid=detectinglocations.locationid AND finds.userid = 1 ORDER BY dateoftrip DESC");
if (mysql_num_rows($result) == 0){
// table is empty
$return = 'There are currently no finds recorded for this location.';
}else{
$return="<table>\n";
while (list($userid, $dateoftrip, $locationname) = mysql_fetch_row($result)){
$return .="<tr>\n".
"<td><input type='radio' name='radio' dateoftrip value='{$userid}' /></td>\n"
."<td><small>{$dateoftrip}</small><td>\n"
."</tr>\n";
}
$return .="<tr><td colspan=\"3\"><br>";
}
?>
<form name="addfinds">
<input name="locationname" type="text" value="<?php echo $locationname;?>" id="locationname" size="80">
<p> </p>
<p>
<?php echo $return;?>
</p>
</form>
你好,非常感謝這一點。我已經修改了我的代碼以包含您的建議並更新了我的原始帖子。但不幸的是,雖然查詢運行,但'locationname'值不填充文本字段。請你可以告訴我哪裏出了問題? – IRHM 2012-02-22 16:15:13
我可以onnly建議你不要使用'list($ userid,$ dateoftrip,$ locationname)'approch並只使用'$ row = mysql_fetch_assoc($ result)'然後存儲'$ locationname = $ row ['locationname']'當通過循環時 – 2012-02-22 16:20:50