Jump to content

search engine pdo


Go to solution Solved by QuickOldCar,

Recommended Posts

I have this function for a search engine using pdo

 

 public function GetPageurlByPagecontent()
{
       $db = Database::getDB(); 
       $query = "SELECT * FROM searchengine where pageurl Like Pagecontent";
       $searchengine =$db->query($query);
       return $searchengine;
}
 
in the data base pagecontent = keyword
 
pageurl is the url to match that keyword
 
this is my form , I want the pagecontent  to match the pageurl only when i do a search by the pagecontent dont even think this query work any ideas?
 
<form action="searchhome.php" method="post" id="search">
  
<b>Enter Search Term:</b> <input type="text" name="term" size="50"> <b>Results:</b> <select name="results">
    <option>10</option>
    <option>20</option>
    <option>50</option>
</select><br>
 
<input type="submit" value="Search">
</form>
<br /> <br />
               
     
 <?php
                if(isset($_POST['pageurl'])){
                $c_name = $_POST['pageurl'];
                
                
$pdb2 = new SearchDB();
$search= $pdb2->GetPageurlByPagecontent($c_name);
                
?>
               
        <h1> Results <?php echo $c_name ?> </h1>
        <?php foreach($search as $list): ?>
        <br /> <br />
<table> 
<tr>
<td>
                                 <p><em> url </em>: <?php echo $list['pageurl'] ?> </p>
 
</td>
</tr>
</table>
                <?php endforeach;  ?>    
<?php }?>
 
       
        
Link to comment
https://forums.phpfreaks.com/topic/287545-search-engine-pdo/
Share on other sites

  • Solution

You need to pass the $_POST value to your function and then to your query

 

 

public function GetPageurlByPagecontent($term)
{
       $db = Database::getDB(); 
       $query = "SELECT * FROM searchengine where pageurl Like '$term'";
       $searchengine =$db->query($query);
       return $searchengine;
}
 
if(isset($_POST['term']) && trim($_POST['term']) != ''){
$term = trim($_POST['term']);
} else {
$term = "something";
}

 

Is there more code to it than this?, surely it wouldn't make a query as is.

 

Is the dropdown select supposed to be a limit on how many results to display?

If so also pass that value into the function and query and add LIMIT

https://dev.mysql.com/doc/refman/5.7/en/select.html

[LIMIT {[offset,] row_count | row_count OFFSET offset}]

 

There is a pagination tutorial here at phpfreaks that would be much better to use.

http://www.phpfreaks.com/tutorial/basic-pagination

 

In my opinion you should get pagination working first and can insert search terms into it

 

Instead of LIKE, you can do a fulltext search which would bring better results and simplify multiple keyword terms

https://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html

Link to comment
https://forums.phpfreaks.com/topic/287545-search-engine-pdo/#findComment-1475091
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.