473,763 Members | 7,622 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple query variables based on str_word_count

Greetings:

I am attempting to split an input string using the str_word_count
function to return multiple single word query variables.
I can create an array based on
$search=(str_wo rd_count($searc h, 1, '0123456789')); (I want words and/or
numbers).
I can extract named variables from the resulting array via
$search=extract ($search, EXTR_PREFIX_ALL , search);
and then call each variable by
$search_0 $search_1 $search_2, etc.
Several issues that I am having:
Since the size of the array is determined by user input. I can't
hardcode $search_x, $search_y, etc. because I don't know what x, y, etc.
will be. How can I produce $search_x... et al. and then hand it/them to
a query string? I can echo desired output using for or while loops,
(i.e. the *value* of $search_x...et al. but I can't figure out how to
get them into query strings. I want my query strings to contain
something like

$q="
SELECT *
FROM *
WHERE table1.row1
LIKE '%$search_x%'
OR LIKE '%$search_y%'
etc..."

Advice or a sanity check is appreciated.

--

Regards,

Jeff Gardner
_______________ ____________

"Contrary to popular belief, Unix is user friendly. It just happens
to be very selective about who its friends are." --Kyle Hearn
Sep 25 '06 #1
2 1513
"Jeff Gardner" <nu**@spamvoid. tldwrote in message
news:_Z******** *********@newss vr13.news.prodi gy.com...
Greetings:

I am attempting to split an input string using the str_word_count function
to return multiple single word query variables.
I can create an array based on
$search=(str_wo rd_count($searc h, 1, '0123456789')); (I want words and/or
numbers).
Stop right here and go no further with the extract thingy. Here you already
have a nice beautiful array, arrays are the coolest, aren't they!? Why go
thru all the trouble with exteracting and such...

You can build up the query conditions with a little implode trick:

$query_conditio ns =
" my_field LIKE '%" . implode( "%' OR my_field LIKE '%", $search) . "%'";

now insert $query_conditio n in your query string:
$q="
SELECT *
FROM *
WHERE table1.row1
LIKE '%$search_x%'
OR LIKE '%$search_y%'
etc..."

HTH

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi. net || Gedoon-S @ IRCnet || rot13(xv***@bhg byrzcv.arg)
Sep 26 '06 #2
Kimmo Laine wrote:
"Jeff Gardner" <nu**@spamvoid. tldwrote in message
news:_Z******** *********@newss vr13.news.prodi gy.com...
>Greetings:

I am attempting to split an input string using the str_word_count function
to return multiple single word query variables.
I can create an array based on
$search=(str_w ord_count($sear ch, 1, '0123456789')); (I want words and/or
numbers).

Stop right here and go no further with the extract thingy. Here you already
have a nice beautiful array, arrays are the coolest, aren't they!? Why go
thru all the trouble with exteracting and such...

You can build up the query conditions with a little implode trick:

$query_conditio ns =
" my_field LIKE '%" . implode( "%' OR my_field LIKE '%", $search) . "%'";

now insert $query_conditio n in your query string:
>$q="
SELECT *
FROM *
WHERE table1.row1
LIKE '%$search_x%'
OR LIKE '%$search_y%'
etc..."


HTH
This is what ended up working:

$table=array(
'table.column',
'table.column2' ,
etc...
);

$str = '';
foreach ($search as $s) {
foreach($table as $t){
if ($str != "")
$str .= "OR\n";
$str.= "$t\n" ;
$str .= "LIKE '%$s%'\n";
}}
$q = "
SELECT
$alias
FROM table1
LEFT JOIN table2
ON table1.id = table2.id
WHERE
$str
";

--

Regards,

Jeff Gardner
_______________ ____________

"Contrary to popular belief, Unix is user friendly. It just happens
to be very selective about who its friends are." --Kyle Hearn
Sep 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
12052
by: jing_li | last post by:
Hi, you all, I am a newbee for php and I need your help. One of my coworker and I are both developing a webpage for our project using php. We have a copy of the same files in different location on the server (in our own accounts on the same machine). When I am testing both versions of our program using the same browser (IE on Windows or Konqueror on Linux) the session variables will mix up and only the latest selection or options will...
11
5411
by: Eugenio | last post by:
Excuse me in advance fo my little English. I've got this stored procedure **************************************************************************** ********** declare @Azienda as varchar(3), @Utente as varchar(20), @DataDa as datetime, @DataA as datetime, @AreaDa as varchar(3), @AreaA as varchar(3),
6
6090
by: BlackFireNova | last post by:
Using Access 2002 I am writing a report which draws data from several different tables. I can't link all the tables in a query, as some can not be related without truncating the data. I plan to use sub-queries and sub-reports to filter and display the data in the unrelated tables in my report. The common information is a user-inputed date range. I want to avoid having the user prompted for the and variables repeatedly. Somehow I...
3
3581
by: Steven Stewart | last post by:
Hi there, I have posted about this before, but yet to arrive at a solution. I am going to try to explain this better. I have an Employees table and a Datarecords table (one-to-many relationship). I have fields called InventoryOut and BalanceEnd that are calculated on the fly for reports and when displayed on forms (they are not part of any table). I have another field called "BalCarFor" (Balance Carried Forward) that is part of the...
2
2193
by: Peter Münster | last post by:
Hello, on page http://www.php.net/manual/en/function.str-word-count.php it's stated that: "For the purpose of this function, 'word' is defined as a locale dependent string" But it does not seem to work, the output of the following script is string(10) "fr_FR.utf8" Array ( =hello =conomie =bla ) I think, that "économie" should be recognized as word.
4
5225
by: Peter Münster | last post by:
Hello, str_word_count() does not seem to work with locale "fr_FR.utf8". The output of the following script is string(10) "fr_FR.utf8" Array ( =bi =re ) I think, that "bière" should be recognized as word. Here is the test-script:
9
3062
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped. Below you will find the code I've written and the error that results. I'm hoping that someone can give me some direction as to what syntax or parameter is missing from the code that is expected by VBA. Overview: I'm trying to copy calculated...
1
4169
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in the whole database. The search form I have now only allows me to filter based on variables in a single table. I would like to have a search form where I can select multiple variables (from various linked tables) to filter by, and return results based on this multi-table filter. Allen Browne...
1
4887
by: KrazyKasper | last post by:
Access 2003 – Multi-Column List Box – Select Multiple Items I have a multi-column (3 columns) list box that works well to select one set of records or all sets of records (based on the first field in the list box). I need to it also select multiple sets of records (Multi-Select = Extended). I modified my code based on code I found on some Internet site which gave an example using three fields in a three field table. It loops through the...
0
10148
Oralloy
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...
0
10002
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
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,...
0
8822
agi2029
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...
1
7368
isladogs
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...
0
5270
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...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.