Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7662421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:47:53+00:00 2026-05-31T13:47:53+00:00

Okay, so my app will find the word you type into the text box

  • 0

Okay, so my app will find the word you type into the text box from a database inside my website.. and it will find the “word” if there is more than 1 “word” it will go through each and pick a random “reply”

How can I do it so that if it can’t find the word “hey” it will look for similar things like “he” etc?

Here’s my PHP:

    <?php
// Connect to database
mysql_connect("server", "db username", "db password");
mysql_select_db("db405677000");

// If something is received
if($_POST)
{
    if($_POST['action'] == "ask")
    {
        // Filter it to prevent SQL injections
        $text = mysql_real_escape_string($_POST['stringdata']);

        // Search it on the database
        $q = mysql_query("SELECT `reply` FROM `poka` WHERE `word` = '$text' ORDER BY RAND()");

        // Show result
        if($r = mysql_fetch_assoc($q))
            echo $r['reply'];
        else
            echo "Cannot find a reply";
    }
    elseif($_POST['action'] == "teach")
    {
        // Filter it to prevent SQL injections
        $word = mysql_real_escape_string($_POST['word']);
        $answer = mysql_real_escape_string($_POST['answer']);

        // Insert it to the database
        if( mysql_query("INSERT INTO `poka` VALUES(NULL, '$word', '$answer')") )
            echo "ok";
        else
            echo "fail";
    }
}
?>

And here is my java part where it actually gets the response:

public void responseGet(String textRequest)
{
    EditText textbox = (EditText)findViewById(R.id.chat);
    textbox.setText("");

    TableLayout chatbox = (TableLayout)findViewById(R.id.chatbox);
    if(canReply == false)
    {
        TableRow tr1 = new TableRow(this);
        tr1.setLayoutParams(new LayoutParams( LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
        TextView textview = new TextView(this);

        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://monaiz.net/get.php");

        String responseStr = "";

        try {
            // Add your data
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("stringdata", textRequest));
            nameValuePairs.add(new BasicNameValuePair("action", "ask"));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity( );

            responseStr = EntityUtils.toString( entity ).replace("\\", "");

        } catch (Exception e) {
            // TODO Auto-generated catch block
        }

        textview.setText(responseStr);
      //  textview.getTextColors(R.color.)
        textview.setTextColor(Color.BLACK);
        textview.setGravity(Gravity.LEFT);

         tr1.addView(textview);

      // Convert dp to px
            int padding_in_dp = 7;
            final float scale = getResources().getDisplayMetrics().density;
            int padding_in_px = (int) (padding_in_dp * scale + 0.5f);

            tr1.setPadding(padding_in_px, 0, padding_in_px, 0);
         tr1.setBackgroundResource(R.drawable.pokaspeak);

         tr1.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent startNewActivityOpen = new Intent(main.this, TeachmeDialog.class);
                    startActivityForResult(startNewActivityOpen, 0);
                }
              });

            chatbox.addView(tr1, new TableLayout.LayoutParams(
                    LayoutParams.FILL_PARENT,
                   LayoutParams.WRAP_CONTENT));
           canReply = true;


           new Handler().postDelayed(new Runnable() {
               @Override
               public void run() {
                ScrollView s = (ScrollView) findViewById(R.id.SV);
                s.fullScroll(View.FOCUS_DOWN);
               }
           },100);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:47:55+00:00Added an answer on May 31, 2026 at 1:47 pm

    You can use PHP function called metaphone.

    There is also a function called soundex that return a numerical code for a word that represents its sound. Words that sound similar will have the same soundex code. You could have a table with words and their soundex codes that you could use to look up similar sounding words. You could then sort them using their levenshtein distance

    Similar to soundex() metaphone creates the same key for similar sounding words. It’s more accurate than soundex() as it knows the basic rules of English pronunciation. The metaphone generated keys are of variable length.

    In MySQL you can make use of the SOUNDEX function. You just need to change your where clause in the query from

     ...WHERE `word` = '$text'...
    

    to

    ...WHERE soundex(word) = soundex('$text')...
    

    or even better you can use SOUNDS LIKE operator as

    ...WHERE word sounds like '$text'...
    

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an app in which there will be user defined categories which will
Okay, I'm trying to create a simple app that will draw a shape (I'm
In my iPad app, there is a UIWebview that displays text content. When I
Okay, so I'm currently developing an iphone app that I plan to take into
Okay so I've setup an app which works fine but there's one problem when
Possible Duplicate: Hide facebook app from search Okay, I know that this question was
i am developing one app which will login to vonage website and do some
Okay I have a large CRUD app that uses tabs with Forms embedded in
Okay this is my first WPF app and I am having a hard run
Okay, I've got my normal app which is in portrait mode. I can force

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.