You will write a very basic web application in PHP that will create a dynamic se
ID: 3810519 • Letter: Y
Question
You will write a very basic web application in PHP that will create a dynamic search form. The PHP script will take user input from the form and perform basic searches on files local to the webserver. Searches will involve JSON objects stored in those files.
The project will create an HTML form with five fields. The field I'm working on is statToFind.
statToFind will be the third <SELECT> field (fourth overall field), also dynamically populated via the Races.json object. The third nested object, "stats", will contain pairs of values in the form:
"index": "statistic"
Example: "S0": "FinishTime"
You should make the VALUE for this SELECT the statistics from this JSON object.
NOTE: You should NOT have any hard-coded "statistics" anywhere in your code. You should expect that the JSON files/objects given are non-exhaustive examples only. statToSearch should be completely dynamic to your program!
Explanation / Answer
we are using php...and sql
atfirst we create a table....
CREATE TABLE SEARCH_ENGINE (
`id` INT(15) NOT NULL AUTO_INCREMENT,
`pageurl` VARCHAR(200) NOT NULL,
`pagecontent` TEXT NOT NULL,
PRIMARY KEY (`id`))
index.php file
====================
<html>
<head>
<title> web search engine </title>
</head>
<body>
< form action = 'search.php' method = 'GET' >
< center >
<h1 > My Search Engine </h1 >
< input type = 'text' size='90' name = 'search' >
</ br >
</ br >
< input type = 'submit' name = 'submit' value = 'Search source code' >
< option > 10 </ option >
< option > 20 </ option >
< option > 50 </ option >
</ center >
</ form >
</ body >
</ html >
data base connection
=====================
mysql_connect ( "localhost", "USER_NAME", "PASSWORD" ) ;
mysql_select_db ( "DB_NAME" );
<?php
$button = $_GET [ 'submit' ];
$search = $_GET [ 'search' ];
if( !$button )
echo "you didn't submit a keyword";
else {
if( strlen( $search ) <= 1 )
echo "Search term too short";
else {
echo "You searched for <b> $search </b> <hr size='1' > </ br > ";
mysql_connect( "localhost","USERNAME","PASSWORD") ;
mysql_select_db("DBNAME");
$search_exploded = explode ( " ", $search );
$x = 0;
foreach( $search_exploded as $search_each ) {
$x++;
$construct = "";
if( $x == 1 )
$construct .="keywords LIKE '%$search_each%'";
else
$construct .="AND keywords LIKE '%$search_each%'";
}
$construct = " SELECT * FROM SEARCH_ENGINE WHERE $construct ";
$run = mysql_query( $construct );
$foundnum = mysql_num_rows($run);
if ($foundnum == 0)
echo "Sorry, there are no matching result for <b> $search </b>. </br> </br>
else {
echo "$foundnum results found !<p>";
while( $runrows = mysql_fetch_assoc( $run ) ) {
$title = $runrows ['title'];
$desc = $runrows ['description'];
$url = $runrows ['url'];
echo "<a href="$url"> <b> $title </b> </a> <br> $desc <br> <a href="$url"> $url </a> <p>";
}
}
}
}
?>
The interface –
interface iindex {
public function storeDocuments($name,array $documents);
public function getDocuments($name);
public function clearIndex();
public function validateDocument(array $document);
}
The search interface –
interface isearch {
public function dosearch($searchterms);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.