PRodgers4284 Posted April 15, 2008 Share Posted April 15, 2008 I have a search facility that using two drop down boxes. Im looking to add a keyword search to this by im not too sure how to, can anyone provide some help/advice? <form method="POST" action=""> <fieldset> <span class="navyboldtxt"> <label for="jobcatergory">Job Category: </label></span> <select name="jobcatergory"> <option value="Please Select">Please Select</option> <?php $jobcatergory_opts = array( "Accountancy and Finance", "Banking and Insurance", "Construction", "Customer Service", "Engineering", "Management", "Hotel and Catering", "Information Technology", "Legal", "Marketing", "Medical", "Retail", "Sales", "Secretarial", "Transport and Distribution", "Working from home", ); foreach($jobcatergory_opts as $opt){ $selected = $_POST['jobcatergory'] == $opt ? " selected=true":""; print "<option value=\"{$opt}\"{$selected}>{$opt}</option>"; } ?> </select><p></p> <p><label for="joblocation"><span class="navyboldtxt">Job Location:</label></span> <select name="joblocation"> <option value="Please Select">Please Select</option> <?php $joblocation_opts = array( "Co.Antrim", "Co.Armagh", "Co.Down", "Co.Fermanagh", "Co.Londonderry", "Co.Tyrone", ); foreach($joblocation_opts as $opt){ $selected = $_POST['joblocation'] == $opt ? " selected=true":""; print "<option value=\"{$opt}\"{$selected}>{$opt}</option>"; } ?> </select><span class="redboldtxt"> </span> </p> <p><span class="redboldtxt"> <?php echo "$joblocation_message";?><?php echo $error['joblocation']; ?></span> <input type="submit" value="Find a Job" name="submit" /></p><p> </p> </fieldset> </form> <?php // how many rows to show per page $rowsPerPage = 4; // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } // counting the offset $offset = ($pageNum - 1) * $rowsPerPage; if ($_POST['submit']){ $select = "SELECT * FROM job"; //MT:Updated + updated $sql = ""; //MT:Added $jobcat = mysql_real_escape_string(trim($_POST['jobcatergory'])); $jobloc = mysql_real_escape_string(trim($_POST['joblocation'])); if ($jobcat != '' && $jobloc != '') { $sql .= " WHERE jobcatergory LIKE '$jobcat%' AND joblocation LIKE '%$jobloc%'"; } else if ($jobcat != '' && $jobloc == '') { $sql .= " WHERE jobcatergory LIKE '%$jobcat%'"; } else if ($jobloc != '' && $jobcat == '') { $sql .= " WHERE joblocation LIKE '%$jobloc%'"; } $limit =" LIMIT $offset, $rowsPerPage"; //MT: ADDED + updated $query = mysql_query($select.$sql.$limit) or die(mysql_error()); //MT: updated if(mysql_num_rows($query) > 0) { while ($job = mysql_fetch_array($query)) { $username=$job["username"]; $id=$job["id"]; $jobtitle=$job["jobtitle"]; $jobcatergory=$job["jobcatergory"]; ?> <table class="sofT" cellspacing="0"> <tr> <td class="Header">Company Name</td> <td class="Header">Job Title</td> <td class="Header">Job Location</td> <td class="Header">View Job</td> <td class="Header">Contact Employer</td> </tr> <tr> <td class="Body"><?php echo $job["username"]; ?></td> <td class="Body"><?php echo $job["jobtitle"]; ?></td> <td class="Body"><?php echo $job["jobcatergory"]; ?></td> <td class="Body"><?php echo "<a href='searchjobview.php?username=$username&id=$id'>View Job</a>"?></td> <td class="Body"><?php echo "<a href='searchemployerdetails.php?username=$username'>Contact Employer</a>"?></td> </tr> <br> </table> <?php } echo '<br>'; echo '<br>'; // how many rows we have in database $query = "SELECT COUNT(id) AS numrows FROM job"; $result = mysql_query($query.$sql) or die('Error, query failed'); //MT: updated $row = mysql_fetch_array($result, MYSQL_ASSOC); $numrows = $row['numrows']; // how many pages we have when using paging? $maxPage = ceil($numrows/$rowsPerPage); // print the link to access each page $self = $_SERVER['PHP_SELF']; $nav = ''; for($page = 1; $page <= $maxPage; $page++) { if ($page == $pageNum) { $nav .= " $page "; // no need to create a link to current page } else { $nav .= " <a href=\"$self?page=$page\">$page</a> "; } } // creating previous and next link // plus the link to go straight to // the first and last page if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\">[Prev]</a> "; $first = " <a href=\"$self?page=1\">[First Page]</a> "; } else { $prev = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\">[Next]</a> "; $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } // print the navigation link echo $first . $prev . $nav . $next . $last; } if($numrows < 1) echo '<p>There are no search results with the search criteria you entered.</p>'; } ?> Link to comment https://forums.phpfreaks.com/topic/101255-keyword-search-help/ Share on other sites More sharing options...
amites Posted April 15, 2008 Share Posted April 15, 2008 huh? please think through your question, I don't think there are any mind readers on this forum Link to comment https://forums.phpfreaks.com/topic/101255-keyword-search-help/#findComment-518024 Share on other sites More sharing options...
PRodgers4284 Posted April 15, 2008 Author Share Posted April 15, 2008 huh? please think through your question, I don't think there are any mind readers on this forum appologies, im need a keyword search to look up a table called "Job" in a field called "description", just too sure how to go about it. Link to comment https://forums.phpfreaks.com/topic/101255-keyword-search-help/#findComment-518042 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.