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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:19:45+00:00 2026-05-28T00:19:45+00:00

I have following code for an autocomplete box, I’m adding an image for choice

  • 0

I have following code for an autocomplete box, I’m adding an image for choice clarification but want to make sure the title returned is unique, but, when I get to the code which makes the array unique, i’ve added other code which makes it non unique in other areas. Is there a way around this?

$query = "SELECT $title, imageURL FROM PRprodINFO2 WHERE ((prodcatID = '$cat_id')
          AND ($title LIKE \"%" . $_GET["q"] . "%\")) group by $title LIMIT 8";
}

$result = mysql_query($query);

// set the array
$output_items = array();

while($row = mysql_fetch_array($result)) { 

    // clean after first non letter/number
    $row[$title] = preg_replace('/[^\w\s].*$/', "", $row[$title]);

    //trim spaces
    $row[$title] = trim($row[$title]);

    // add image src
    $output_items[] = '<img src='.$row[imageURL].' style=max-width:50px;>'
                      .$row[$title]; 

} // while

// here i need just $row[title] to be unique,
// it is made non unique after regex strips off some characters
$output = array_unique($output_items);

print(implode("\n", $output));

mysql_close();
  • 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-28T00:19:45+00:00Added an answer on May 28, 2026 at 12:19 am

    I am possibly confused by what you are asking. It seems like you would already have unique titles since you are grouping by title in your sql. But, maybe you have extra non alpha-numeric characters you are stripping out with your regex that makes some unique titles the same.

    In that case, instead of building up your $output_items like you are, try:

    $output_items[$row['title']] = $row['imageURL'];
    

    This will ensure that each title is unique. You will have the imageURL of the last row that matched that title. If you want, instead, the first title that matched, then just check isset before overwriting it like:

    if (!isset($output_items[$row['title']])) $output_items[$row['title']] = $row['imageURL'];
    

    Then, outside of the loop, build up your output string.

    $output = '';
    foreach ($output_items as $title => $image) {
        $output .= '<img src='.$image.' ...>'.$title."\n";
    }
    echo $output;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that gives me a an array in an autocomplete
I have the following set up, a ddl (ddlProd, radBuyer) and autocomplete text box
I have the following code to parse the country when the autocomplete list is
I am using jQuery autocomplete pluggin . I have the following code $().ready(function() {
I have following code in html: <div> <div style=float:left;margin:0.5em> <span class=title>Label1</span><br/> <input type=text name=name1
I have the following code: $(#auto).autocomplete({ source: js/search.php, minLength: 3 }); This code is
I have the following code: // Autocomplete search $(#shop_search).autocomplete({ source: '<%= spotify_search_path(:json) %>', minLength:
I have the following code - http://jsfiddle.net/vcvsb/1/ - per $(document).ready(function(e) { $(input#autocomplete).autocomplete({ source: [c++,
I am implementing the Jquery UI autocomplete. I have the following code. Application.js $(function()
I have an autocomplete text box that users can type an item code into

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.