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.

  • Like 1
Link to comment
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.