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 8048339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:24:03+00:00 2026-06-05T06:24:03+00:00

I currently have this table. Names Two fields, ID and Names. Example data would

  • 0

I currently have this table.

Names

Two fields, ID and Names. Example data would be 1 | Harry.

Now what i am planning on doing is that if someone enters in something like Henry in my form, it will search my database for a result that begins with “H” Then if their are multiple results, it will see if there are any results that are “He” if their isn’t it will fallback to the previous result from “H”.

The only thing i can think of doing is this,

$inputted_name = "Henry";
$query = mysql_query("SELECT `name` FROM `names`");
while($row = mysql_fetch_array($query)){
    $stored_name = $row['name'];
    if($stored_name[0] == $inputted_name[0]){
        if($stored_name[1] == $inputted_name[1]){
            $result = $stored_name;
            break;
        }   else   {
            // continue looking but then return the first result that matched one letter?
        }
    }
}

Now i am sure this can’t be the best way to do it. Would it be possible in a query? I’m just really not sure where to look for a sensible answer for this one.

  • 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-06-05T06:24:05+00:00Added an answer on June 5, 2026 at 6:24 am

    change
    mysql_query(“SELECT name FROM names“);

    to
    mysql_query(“SELECT name FROM names WHERE NAME='”.$inputted_name.”‘”);

    and check you have more than one answer.

    Note this is a bad way to do it if your name comes from a non controlled source, such as a web page, as it would allow a SQL injection, and then you would need parameters, but for your example it would work.

    Edit: Now I read your question again, yes, you would need parameters or escaping such as:

    $name = mysql_real_escape_string($inputted_name);
    mysql_query("SELECT `name` FROM `names` WHERE NAME='".$=name."'");
    

    Also, don’t try and do in code what the database can do easily (like search for characters). Your code is almost always going to be worse than the database for doing a search, leave it to the database.

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

Sidebar

Related Questions

I currently have a table structure that looks something like this(some details omitted): ColumnName
I have a successful query that currently returns all data except for one table.
I currently have the following row in my table: course_data: user_id days <-- This
I have a table which currently looks a bit like this- CASEID ¦ FORMNAME
I currently have this working fiddle - http://jsfiddle.net/B8Abd/ I would like to use jquerys
I currently have this script : function addConsultant() { var sheet_staffing = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(Staffing); var
I currently have this query: SELECT s_id FROM orderline,order_t WHERE orderline.o_id=order_t.o_id AND c_name='John Smith';
I currently have this but it's not flawless: $testcases = array( array(I love mywebsite.com,
I currently have this solution to change the css elements when the page reaches
I currently have this... sanitizeNumber = function ( dirtyNumber ){ // remove any non-digits

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.