我在 php 中有 3 页。第 1 页包含一个搜索表单,用户在其中输入要在我的数据库中搜索的名称:
<form method="get[value]" name="go" action="search_form_all.php" >
<input name="value" type="text" id="search_form_1" size="65" autocomplete="off" placeholder=" Search People ..." />
<input type="submit" value="" name="submit" />
</form>
第 2 页包含一个 php 脚本,该脚本获取用户在搜索表单(第 1 页)中输入的值,并成功返回我的数据库中的所有名称。
$value = mysql_real_escape_string($_GET['value']);
$name_and_surname = explode(" ", "$value ");
$name = $name_and_surname[0];
$surname = $name_and_surname[1];
$sql = " SELECT `name`, `surname`, `email`, `user_id` FROM users WHERE (surname LIKE '$name%' AND name LIKE '$surname%') OR (surname LIKE '$surname%' AND name LIKE '$name%') ";
$result = mysql_query($sql);
while($run = mysql_fetch_array($result)){
$surname = $run['surname'];
$name = $run['name'];
echo"<a href='profile_full.php?email=$email'> $surname $name </a>";
}
//page until now prints all names that user enters in search form.
//In order to give user the option to display all names that are from a certain country, bellow I use this code:
<form method="get[value]" name="go" action="location.php" >
<select name="country">
<option value=" "> select </option>
<option value="Afganistan">Afghanistan</option>
<option value="Albania">Albania</option>
</select>
<input type="submit" value="go" />
问题从第 3 页开始,它应该显示用户在第 1 页的搜索表单中输入的所有名称以及在第 2 页中选择的国家/地区。
第 3 页如下:
$value = mysql_real_escape_string($_GET['value']);
$name_and_surname = explode(" ", "$value ");
$name = $name_and_surname[0];
$surname = $name_and_surname[1];
$sql = " SELECT u.name,
u.surname,
u.email,
u.user_id,
p.user_id
FROM users u
INNER JOIN profile p ON p.country = '$value'
WHERE u.surname LIKE '$surname%' AND u.user_id = p.user_id ";
$result = mysql_query($sql);
while($run = mysql_fetch_array($result)){
$surname = $run['surname'];
$name = $run['name'];
echo"<a href='profile_full.php?email=$email'> $surname $name ";
}
如何修改第 3 页中的代码,以便它从第 1 页(用户想要查找的名称)和第 2 页(这些名称所在的国家/地区)中获取值。