"; print "Properties with search term " . $searchVal . " are:-
";//display the users search input value $query = sqlite_query($dbhandle, 'SELECT * FROM PROPERTY'); //select all from table property, dbhandle=database ref, dat to $query $result = sqlite_fetch_all($query, SQLITE_NUM); //get the query, using numeric referencing, put into result foreach ($result as $lineArray) //result is an array of an array, ie result[0], result[1] and so on, i.e result[0] is a row that contains lineArray[0] [1] [2] [3] { // result[1] is a row that contains lineArray[0] [1] [2] [3] for ($x=0;$x<4;$x++) //loop 0,1,2,3 { $rowValue = $lineArray[$x]; //put each lineArray value into $rowValue, using $x to provide array number $strSearch = $searchVal; //puts the search value into variable strSearch $strSearchLength = strlen($strSearch); //measures length of word of search and puts into variable $strAWordLength = strlen($rowValue); //measures length of the word in $rowValue( the array of array) for($i=0; $i<($strAWordLength-$strSearchLength+1); $i++) // add 1 to accommodate 0 start { $aWordChunk = getItem($rowValue,$i,$strSearchLength); //call to function get item, pass values, put into variable if ($strSearchLength>1) //adjustment to stop duplicate entries appearing due to lowercase change { $aWordChunk = strtolower($aWordChunk); //to accommodate upper and lower case $searchVal = strtolower($searchVal); //to accommodate upper and lower case } if ($aWordChunk==$searchVal) //if a match is found { $rowValue0 = $lineArray[0]; //put word into $rowValue0 $rowValue1 = $lineArray[1]; //put word into $rowValue2 $rowValue2 = $lineArray[2]; //put word into $rowValue3 $rowValue3 = $lineArray[3]; print $rowValue0 . " "; print $rowValue1 . " "; print $rowValue2 . " "; print $rowValue3 . " "; print "
" ; break; } } } } function getItem($text, $startNumber, $noOfLetters) //this function reads a certain number of letters, from a start point { return substr($text, $startNumber, $noOfLetters); #substr(text, start_char, number_of_chars) } sqlite_close($dbhandle); ?>
Search
"; print_r( $result); print ""; ?>