Hi,
I am trying to find the records based on a search string which can be anything and can match any of the varchar fields in the table. Right now i am getting those records by using the combinations of "LIKE" and "OR" operators.But as per the requirements i also need to show the number of occurences of the search string that could match different varchar fields in a record?? Can anyone please suggest me how can i prepare this query??
Thanks,
Lauren
3 2470
Number of occurence of the string or number of records the string occurs on? Post your current query?
For number of record mysql_num_rows( $result)
If its counting the number of occurences of the string in the fields of all records. You could loop through the records it detected the string in and do a string level search.
Hope I understood the question correctly. :D
Below is the query:
SELECT DISTINCT Master_A.ID,Mas ter_A.Name,Mast er_A.Descriptio n FROM Master_A INNER JOIN Details_A ON Master_A.ID = Details_A.A_ID WHERE Master_A.Status = 1 AND Details_A.Statu s = 1 AND (Master_A.Name LIKE '%pattern%' OR Master_A.Descri ption LIKE '%pattern%' OR Details_A.Code LIKE '%pattern%');
The above query is returning back all those records based on the conditions and the search pattern, which is performed on all the probable varchar fields contained by the tables. As per the requirements i need to show the number of occurences at record level, i.e. ,if the search string is contained by Master_A.Name,M aster_A.Descrip tion for a record, then the number of occurences should be equal to 2 for that record.
Thanks,
Lauren
Whats your server side programming language?
Im affraid Im only experienced in PHP and would do it like this... - $pattern = "cheese";
-
-
$query = "SELECT DISTINCT Master_A.ID,Master_A.Name,Master_A.Description FROM Master_A
-
INNER JOIN Details_A ON Master_A.ID = Details_A.A_ID
-
WHERE Master_A.Status = 1 AND Details_A.Status = 1 AND
-
(Master_A.Name LIKE '%pattern%' OR Master_A.Description LIKE '$pattern' OR Details_A.Code LIKE '$pattern')";
-
-
$result = mysql_query($query);
-
-
$occurences = 0;
-
while($row = mysql_fetch_assoc($result))
-
{
-
$occurences += substr_count($row['Name'],$pattern);
-
$occurences += substr_count($row['Description'],$pattern);
-
}
-
-
echo $occurences;
Im sure this can be done in any server side code.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Liz Malcolm |
last post by:
Hello and TIA for guidance.
I am building a reusable search procedure (thanks go to Graham Thorpe
for his example that set me on my way). Everything works up until the
2nd match is found, the command doesn't go to the third match, it
exits out of the loop. I've read everything I could find in NG's, but
I can't figure out where I'm going wrong. Here is my code.
Function cmdSearch(ctlSearchText As Control, ctlFoundText As Control,...
|
by: M.N.A.Smadi |
last post by:
hi;
say i have a text file with a string ( say '(XYZ)') and I want to find
the number of line where this string has occured. What is the best way
to do that?
what about if that string was say a 0 with leading and trailing white
spaces, would that be any different?
thanks
moe smadi
|
by: Dameon |
last post by:
Hi All,
I have a process where I'd like to search the contents of a file(in a dir)
for all occurences (or the count of) of a given string. My goal is to focus
more on performance, as some of the files could be upwards of 25mb in size
and time is important. I don't want to take the route of loading the text of
the file into a giant string and searching it, but would rather focus on a
performance-minded solution. Any sugesstions for a...
|
by: Daneel |
last post by:
Hello!
I'm looking for an algorithm which finds all occurences of a bit
sequence (e.g., "0001") in a file. This sequence can start at any bit
in the file (it is not byte aligned).
I have some ideas of how to approach the problem (1) reading file into
unsigned char buffer, 2) defining bit structure, 3) comparing the
first 4 bits of the buffer with the bit structure, 4) shifting the
char buffer one left, 5) repeat at step 3)) but I'm...
|
by: shubharamaswamy |
last post by:
Reading standard input and printing the number of occurences of each letter in graphic format as follows:
a: .....
b: ..
.
.
.
z: ...
where no. of dots= no.of occurences
| |
by: mustang07 |
last post by:
I need this program to find all occurences of a name and display them.
If I enter Palmer, I need it to display all the Palmers in the list.
Can anyone help me Please. Thank You!!
#include <iostream>
#include <string>
using namespace std;
int main()
|
by: Larry |
last post by:
Dear all,
I'm new to Python. I have a file (an image file actually) that I need
to read pixel by pixel. It's an 8-bit integer type. I need to get the
statistics like mean, standard deviation, etc., which I know a little
bit already from reading numpy module. What I want to know is how to
get the number of occurences of numeric element in an array. Say,
b = array(()
|
by: ajhayes |
last post by:
I posted a few weeks ago about trying to set up a way to order by unit number (http://bytes.com/topic/access/answers/864507-need-help-setting-up-table-structure-ordering-unit)
I'm trying to use a similar structure to what OldBirdman suggested in my previous post, but I'm a bit stuck.
Here is what I've set up:
tbl_Orders
Order_Number
Order_Date
|
by: lilly07 |
last post by:
I am trying open a text file, and find the occurence of first column string (ie) $v in a separate file which contains only one column.
my code is as follows but somehow it doesn't seem to count the number of occurences in the second file.
#!/usr/bin/perl -w
$datafile = $ARGV;
print "$datafile\n";
open (LIST1, $datafile) || die "File not found\n";
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |