I am required to return a search result using only one keyword, how do I do this in PHP?
-
This question was hard to word. We have script in PHP and HTML and we are required to modify the script so that when we enter only one search query, the data with all of that query in it is returned. The example we are given is of prime ministers. Just say I enter John. The result returned must include all prime ministers with the name John along with displaying their year, state, party, etc. Here is the PHP code in "defs.php": <?php /* Functions for PM database example. */ /* Load sample data, an array of associative arrays. */ include "pms.php"; /* Search sample data for $name or $year or $state from form. */ function search($name, $year, $state) { global $pms; //should make another variable called $input? // Filter $pms by $name if (!empty($name)) { $results = array(); foreach ($pms as $pm) { if (stripos($pm['name'], $name) !== FALSE) { $results[] = $pm; } } $pms = $results; } // Filter $pms by $year if (!empty($year)) { $results = array(); foreach ($pms as $pm) { if (strpos($pm['from'], $year) !== FALSE || strpos($pm['to'], $year) !== FALSE) { $results[] = $pm; } } $pms = $results; } // Filter $pms by $state if (!empty($state)) { $results = array(); foreach ($pms as $pm) { if (stripos($pm['state'], $state) !== FALSE) { $results[] = $pm; } } $pms = $results; } return $pms; } ?> I have to modify the search function. If you need any other parts of the code, like the results.php code which prints the results in a formatted table, just comment.
-
Answer:
Make sure you enter the state result into the program. Then check again.
PB's Boys at Yahoo! Answers Visit the source
Related Q & A:
- How can I check captcha with PHP?Best solution by Stack Overflow
- When I click on my Internet explorer, It logs me automatically into yahoo, How do I change this?Best solution by Yahoo! Answers
- When i do a search and click on a result a get a page addressed rc10 overture what do i do?Best solution by Yahoo! Answers
- How to search for a particular string in a text file using java?Best solution by Stack Overflow
- Can I take a picture of myself using my webcam and how do I do it?Best solution by Super User
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.