How to return result of function?

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

Was this solution helpful to you?

Find solution

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.