Jump to content

PHP:search user input into database


amk

Recommended Posts

Hello,

I am trying to create a scripts that takes the user input. For example, a text and searches every word from the text in an already created database. Then the same text is displayed and the words are coloured based on their rank.

 

Up till now this is what i have:

<?php
                                        $query=$_GET['query'];

                                        if (isset($_GET['submit'])){
                                             //$result1=$_GET['query'];
                                            $words = explode(' ', $query);

                                            $queryDB ="SELECT `Word` FROM `WordFrequencyList` WHERE ";

                                            $conds = array();




                                            foreach ($words as $val) {
                                                $conds[] = "WordFrequencyList.Word LIKE '".$val."'";


                                                }
                                            $queryDB .= implode(" ", $conds);

                                            $final=mysql_execute($queryDB);


?>

The code only separates the text into words. How can i fetch these words from the database after the text has been separated into words?

 

 

Link to comment
Share on other sites

Not sure what you mean by your last point. The code seems to be building a query statement almost perfectly. Your only problem is when you do your implode you need to add " and " instead of just the space.

 

Also - you really need to STOP using the MySQL functions. They are deprecated. See the manual. Switch to mysqlI or better yet to PDO.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.