Интересно, может ли кто-нибудь помочь мне.Значение поля эха в текстовом поле
С помощью некоторых рекомендаций, которые я получил ранее с этого сайта, мне удалось собрать сценарий, ниже которого перечисляется информация о дате с помощью связанного переключателя, позволяющего выбирать каждую запись.
<?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
Я могу предположить, что вы не используете 'list ($ userid, $ dateoftrip, $ locationname)' approch и просто используйте '$ row = mysql_fetch_assoc ($ result)' then store '$ locationname = $ row ['locationname']' при прохождении цикла –