suria Posted August 14, 2010 Share Posted August 14, 2010 Hi there, I am new to PHP & Mysql and I have managed to build a basic search page. please see the code below Currently i am able to select single field type and search within.... I would like to search multiple fields at the same time and return the matching E.g. FieldType = Sounds User input = ? FieldType = Generic User input = ? FieldType = Activity User input = ? SEARCH BUTTON RESULT Echo story ID of matching all input in one row and how many in total Echo story id of matching Two user search and how many in total Echo Story id of matching One and how many in total Thank you..and please ask me if i didn't make sense..thanks again -----search page $searchtype=$_POST['searchtype']; $searchterm=trim($_POST['searchterm']); if (!$searchtype || !$searchterm) { echo 'You have not entered search details. Please go back and try again.'; exit; } if (!get_magic_quotes_gpc()){ $searchtype = addslashes($searchtype); $searchterm = addslashes($searchterm); } @ $db = new mysqli('localhost', 'root', 'pass', 'dbname'); if (mysqli_connect_errno()) { echo 'Error: Could not connect to database. Please try again later.'; exit; } $query = "select * from stories where ".$searchtype." like '%".$searchterm."%'"; $result = $db->query($query); $num_results = $result->num_rows; echo "<p>Number of records found: ".$num_results."</p>"; for ($i=0; $i <$num_results; $i++) { $row = $result->fetch_assoc(); echo "<strong> <br />Stor ID:</strong> "; echo stripslashes($row['id']); echo..... } $result->free(); ----- form page <form action="search.php" method="post"> Search by Person:<br /> <select name="searchtype"> <option value="sounds">Sounds</option> <option value="generic">Generic</option> <option value="activity">Activity</option> </select> <br /> Enter Search Term:<br /> <input name="searchterm" type=”"text" size="40"/> <br /> <input type="submit" name="submit" value="Search"/> </form> ----- Quote Link to comment Share on other sites More sharing options...
suria Posted August 16, 2010 Author Share Posted August 16, 2010 can anyone help me with the query and the form please... thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.