473,322 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

search query troubles

32
I want to grab the info for a part where the part is associated with the printer being displayed, and the client has access to that specific printer.

Expand|Select|Wrap|Line Numbers
  1. SELECT part_id, part_info FROM parts WHERE MATCH( SELECT printer_id FROM parts_printer WHERE parts.part_id = parts_printer.part_id ) AGAINST($this->printerArray);
  2.  
for most parts, the printer_id will actually result in an array or printers, rather than a single printer... will the match clause check each printer in the partprinter array to the usersprinters ($this-printerArray) that is located in the session.

and also, if it does match one of printers, will it abort the search for that part? because I already know the part belongs to that printer, and if the user has access to the printer, there is no need to check if there the user has access to another printer in the range of possibilities
Aug 17 '07 #1
3 1223
pbmods
5,821 Expert 4TB
Heya, jgentes.

You posted this in the Articles section. I'll go ahead and move it to the Forum where an Expert will be more likely to find it.

MATCH ( ... ) AGAINST ( ... ) is for fulltext searches. Did you mean to do this instead:
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.         `parts`.`part_id`,
  3.         `parts`.`part_info`
  4.     FROM
  5.     (
  6.             `parts`
  7.         LEFT JOIN
  8.             `parts_printer`
  9.                 USING
  10.                     (`part_id`)
  11.     )
  12.     WHERE
  13.         `parts_printer`.`printer_id`
  14.             IN ($this->printerArray)
  15.  
Or perhaps...
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.         `parts`.`part_id`,
  3.         `parts`.`part_info`
  4.     FROM
  5.     (
  6.             `parts`
  7.         LEFT JOIN
  8.             `parts_printer`
  9.                 USING
  10.                     (`part_id`)
  11.     )
  12.     WHERE
  13.         `parts_printer`.`printer_id`
  14.             IN
  15.             (
  16.                 "' . implode('", "', $this->printerArray) . '"
  17.             )
  18.  
Aug 17 '07 #2
jgentes
32
oops, when i originally posted this I forgot the initial clause. I chose to use MATCH(...) AGAINST(...) because there is a search term that is getting passed from the client... sorry. I originally was going to use part_info LIKE %$search% but i thought a full text search would be better, as 'part_info' is really a collection of 3 fields to search.

so would
Expand|Select|Wrap|Line Numbers
  1. SELECT `part_id`, `number`, `description` FROM `parts` 
  2.    LEFT JOIN `parts_printer` USING(`part_id`) 
  3.    WHERE (`number` LIKE %". mysql_real_escape_string($search) ."% 
  4.       OR `description` LIKE %". mysql_real_escape_string($search) ."% 
  5.       OR `keyword` LIKE %". mysql_real_escape_string($search) ."%) 
  6.    AND ...
  7.  
be better or
Expand|Select|Wrap|Line Numbers
  1. SELECT `part_id`, `number`, `description` FROM `parts` 
  2.    LEFT JOIN `parts_printer` USING(`part_id`) 
  3.    WHERE [COLOR=BLUE] MATCH(`number`, `description`, keywords`)
  4.       AGAINST(`$search`) [/COLOR]
  5.    AND ...
  6.  
My only question about which 'ending' to use is which one of them when it returns true jumps out of the loop and moves to the next record in the table? I say this because I already know that part is associated with the printer, and the user has access to that printer, so there is no sense in having it search through the rest of the array.

On a side note this is going to loop through all of the printers individually correct, so would it be better to just use the implode method? and use SELECT DISTINCT, as a means to rid the resulting array of duplicate entries?
Aug 17 '07 #3
pbmods
5,821 Expert 4TB
Heya, jgentes.

In this case, you are probably going to want to use the first query, as this will return the most accurate result set.

Using fulltext searching can cause 'fuzzy' results; that is, you may get results that don't contain any of the search terms but that are similar to what the User searched for.

To answer your question, the first query will "short-circuit" after the first TRUE for maximum efficiency. However, with fulltext searching, MySQL uses ALL of the search terms (because it's a different kind of search than the LIKE comparison).
Aug 17 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Polar | last post by:
I am having troubles finding the parse error in this script. I've been checking for weeks. I am too new to the subject I guess. I am trying to show a readord and them have a form at the bottom...
2
by: TH | last post by:
I am (still :) working on a recipe database. Now I am trying to figure out how to set it up for an ingredient search. What I want it to be able to do is to search by one ingredient, sometimes by...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
5
by: Simon Jans | last post by:
Hello I'm having serious troubles creating a seach form showing data from multiple tbls, I'll try to explain my problem using a simple example by the way I'm using Acces 2003 tblEquipment ...
1
by: cglewis03 | last post by:
Hello, I am trying to build a search form with several different options to choose from. Currently it is set up to open within the same window if a single option is selected and open within a...
13
by: jfarthing | last post by:
Hi everyone! I am using the script below to search a db. If the is more than one match in the db, all goes well. But if there is only one match in the db, nothing gets displayed. Any...
13
by: Robertf987 | last post by:
Hi, Yet another thing I need help with I'm affraid. I'll first explain what I want, then I'll try to explain what I have. I'm using Microsoft Access 2000. What I want is to be able to do a...
3
nathj
by: nathj | last post by:
Hi, I am just trying to develop a search system for my website. The PHP side of things is no trouble at all. I have also set up what I think are appropriate FULLTEXT indices on the tables I will...
8
by: Miro | last post by:
Hi sorry for the quick question. I am on the right track but just cant seem to find what to search for in my books / online for the answer I am looking for. I have created a dataset within my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.