내 메인 페이지 - index.php에있는이 양식의 데이터를 사용하려고했습니다.PHP를 사용하여 <select> 태그에서 데이터를 수집
이include "all/config.php";
$search = $_REQUEST['search']; //Getting the words
$split = split(" ",$search); //If there is more than one I spit them.
foreach ($split as $array => $value)
{ $NewResult .= $value;
}
$wheretosearch = $_POST['wheretosearch'];
if ($wheretosearch = 'Articles')
{$Results = mysql_query("SELECT * FROM bgarticles WHERE title LIKE '%$value%' OR description LIKE '%$value%' OR text LIKE '%$value%' OR tags LIKE '%$value%' OR date LIKE '%$value%' OR author LIKE '%$value%' OR ip LIKE '%$value%' ");
while($row = mysql_fetch_array($Results))
{
echo "<div class='top'>";
echo "<span class='title'>";
echo "<a href=details.php?id=$row[id]>";
echo $row['title'];
echo "</a>";
echo "</span> <br><br>";
echo "<span class='author'>";
echo $row['author'];
echo "</span>";
echo "<span class='date'> Date: ";
echo $row['date'];
echo "</span> <br><br><br>";
echo "<br><br></div>" ;
echo "<div class='bottom'><br><br></div>";
}
}
if ($wheretosearch = 'members')
{$Results2 = mysql_query("SELECT * FROM members WHERE username LIKE '%$value%' OR firstname LIKE '%$value%' OR lastname LIKE '%$value%' ");
while($row2 = mysql_fetch_array($Results2))
{
echo "<div class='top'>";
echo "<span class='title'>";
echo "<a href=details.php?id=$row2[id]>";
echo $row2['username'];
echo "</a>";
echo "</span> <br><br>";
echo "<span class='author'>";
echo $row2['firstname'];
echo "</span>";
echo "<span class='date'> Date: ";
echo $row2['date'];
echo "</span> <br><br><br>";
echo "<br><br></div>" ;
echo "<div class='bottom'><br><br></div>";
}
}
내가 할 상관없이 항상 두 MySQL의 테이블에서 데이터를 보여줍니다
<center>
<form action="search.php" method="post">
<input type="text" name="search" size="30" />
<select name='wheretosearch'>
<option value='Articles'>Articles</option>
<option value='Users'>Members</option>
</select>
<input type="submit" value="Search" />
</form>
</center>
이 search.php 코드의 주요 부분이다. 왜? 솔직히
* (관련 항목) * [$ _REQUEST를 $ _POST (으)로 변경해야합니까?] (http://stackoverflow.com/questions/2987447/should-i-change-request-to-post/2987468#2987468) – Gordon