Tuesday, 9 June 2020

how to print the text which is matched with this word or letters we entered

how to print the text which is matched with this word or letters we entered
lesson 46
creating serch engine
<?php
require 'lesson44.php';
get the template
?>
create a form with method is search
<form action = "searchengine.php" method = "post">
search: <input type= "text" name ="s_text">
<input type= "submit" value="search">
</form>


<?php

if (isset ($_POST ['s_text'])){
whenerver post is submitted
$s_text = $_POST ['s_text'];
get the data which data is sumitted

if(!empty ($s_text)){
if some data is submitted
$query = "SELECT `name` FROM `foods` WHERE `name` LIKE '%$s_text%' ";
seelct name column from foods table and search name like entered text

$query_run = mysqli_query($mycon, $query);
run this query against database, we filter some outputs
$num_rows = mysqli_num_rows($query_run);
after filtered, find number of rows
//how many rows findout with this query
//echo $num_rows;
print the number of rows
//we asked using query get the data from user, select name column from foods data base and chek name like enter text

if ($num_rows >= 1) {
we got some rows, if that filtered rows is greater than one
echo '<h1>' .$num_rows.'results found</h1>';
print number of rows
while ($row = mysqli_fetch_assoc($query_run)){
convert to array , get the row of name
echo $row['name']. '<br><br>';
}
}else{
echo 'no results found';
}


}
}

?>

















how to get the other webpage template require
form html action
tupe
how to know customer is submitted or not isset $_post
not empty !empty
query SELECT FROM
WHERE LIKE
how to execute query mysqli_query
how to find number of rows after filtered mysqli_num_row
mysqli_fetch_assoc
$row['name']

No comments:

Post a Comment