私は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 には、ユーザーが (ページ 1 の) 検索フォームに入力した値を取得し、データベースからすべての名前を正常に返す php スクリプトが含まれています。
$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 ";
}
ページ 1 (ユーザーが検索したい名前) から値を取得し、ページ 2 (これらの名前が存在する国) から値を取得するように、ページ 3 のコードを変更するにはどうすればよいですか。