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

  • Home
  • SEARCH
  • 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 3699068
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:03:30+00:00 2026-05-19T05:03:30+00:00

I’ve been asked to add a small AJAX feature to a clients site. Basically

  • 0

I’ve been asked to add a small AJAX feature to a clients site. Basically I have a MySQL table with 3 fields:

  • id
  • product
  • name

The idea of the site is that the user starts typing the “name”, and the products show up after a couple of keystrokes. My query looks like this:

$query = mysql_query("SELECT product FROM mytable WHERE name LIKE '%".$search."%'");

Everything works, except when there is a space in the “name”. For example, if I have a name called “Coca Cola”, the script successfully lists the product when I type “Coca”, but as soon as I type the space, it no longer returns any rows.

I’ve searched everywhere for a solution. I understand that the space is interpreted as a separator of some kind, but can I get the database to interpret the space as … well … a space? If not, is there a better way of doing what I want to accomplish?

EDIT:

I ran it in PHPMyAdmin and it actually returns the correct results, which leads me to believe that it must be something in the PHP. Theres the full script:

$search = $_GET['search'];
$already_echoed = array();

if (!ereg('[^A-Za-z0-9]', $search) && strlen($search) > 2) {

 $query = mysql_query("SELECT product FROM mytable WHERE name LIKE '%".$search."%'");

 if (mysql_num_rows($query) > 0) {

  echo '<h4>Suggestions:</h4><ul>';

  while ($product = mysql_fetch_array($query)) {

   if (!in_array($product['product'], $already_echoed)) {
    $getProduct = mysql_query("SELECT name, shortname FROM products WHERE id='".$product['product']."'");
    $product2 = mysql_fetch_array($getProduct);

    echo '<li><a href="http://' . $product2['shortname'] . '.mydomain.com">' . $product2['name'] . '</a></li>';
    $already_echoed[] = $product['product'];
   }

  }

  echo '</ul>';

 }


}
  • 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-19T05:03:31+00:00Added an answer on May 19, 2026 at 5:03 am
    !ereg('[^A-Za-z0-9]', $search
    

    Looks like you’re excluding spaces from the allowed list of characters. I don’t speak much PHP and can’t be arsed to go look at the docs.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm looking for suggestions for debugging... If you view this site in Firefox or
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6

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.