Unix Technical Forum

Data from 2 columns

This is a discussion on Data from 2 columns within the MySQL forums, part of the Database Server Software category; --> Hi all, I have what I hope is a simple question.... I have a table with several columns, the ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:27 AM
JimJx
 
Posts: n/a
Default Data from 2 columns

Hi all,
I have what I hope is a simple question....

I have a table with several columns, the 2 I am concerned with at the
moment are Category and Keywords.

I need to search both of these columns for a word or short phrase that
I get from a form.

For example, the search can be 'Antiques' or 'Antique Dealers'

I tried to use this

SELECT name, address, city, phone
FROM valley
WHERE keywords OR category
LIKE '%$search%'
ORDER BY name LIMIT %d,%d"

in several different ways but no joy.

When I use that snippet of code, I will get any matches from
'keywords' but nothing from category, even though I know there is a
category with the var in it....

Example:
If the form passes 'auto' and I have an entry in keywords for 'auto
dealers' and a category for 'auto repair', I will get the auto
dealers, but not the auto repair.....

Any ideas?

Thanks,
Jim

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 11:27 AM
Good Man
 
Posts: n/a
Default Re: Data from 2 columns

JimJx <webmaster@valleywebnet.com> wrote in news:1190316521.493308.312510
@k79g2000hse.googlegroups.com:

> Hi all,
> I have what I hope is a simple question....
>
> I have a table with several columns, the 2 I am concerned with at the
> moment are Category and Keywords.
>
> I need to search both of these columns for a word or short phrase that
> I get from a form.
>
> For example, the search can be 'Antiques' or 'Antique Dealers'
>
> I tried to use this
>
> SELECT name, address, city, phone
> FROM valley
> WHERE keywords OR category
> LIKE '%$search%'
> ORDER BY name LIMIT %d,%d"
>


SELECT name,address,city,phone
FROM valley
WHERE keywords LIKE '%$search%'
OR category LIKE '%$search%'
ORDER BY name LIMIT %d,%d



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 11:27 AM
JimJx
 
Posts: n/a
Default Re: Data from 2 columns

On Sep 20, 3:36 pm, Good Man <he...@letsgo.com> wrote:
> JimJx <webmas...@valleywebnet.com> wrote in news:1190316521.493308.312510
> @k79g2000hse.googlegroups.com:
>
>
>
> > Hi all,
> > I have what I hope is a simple question....

>
> > I have a table with several columns, the 2 I am concerned with at the
> > moment are Category and Keywords.

>
> > I need to search both of these columns for a word or short phrase that
> > I get from a form.

>
> > For example, the search can be 'Antiques' or 'Antique Dealers'

>
> > I tried to use this

>
> > SELECT name, address, city, phone
> > FROM valley
> > WHERE keywords OR category
> > LIKE '%$search%'
> > ORDER BY name LIMIT %d,%d"

>
> SELECT name,address,city,phone
> FROM valley
> WHERE keywords LIKE '%$search%'
> OR category LIKE '%$search%'
> ORDER BY name LIMIT %d,%d


Good Man, Thanks for the reply!

I have a question though..... When I run this query through
phpMyAdmin, it works fine. However, when I run it through my web site
I get nada. <!?!>

Any ideas on this?

Thanks!
Jim

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 11:27 AM
Good Man
 
Posts: n/a
Default Re: Data from 2 columns

JimJx <webmaster@valleywebnet.com> wrote in
news:1190318015.423871.244970@r29g2000hsg.googlegr oups.com:

> On Sep 20, 3:36 pm, Good Man <he...@letsgo.com> wrote:
>> JimJx <webmas...@valleywebnet.com> wrote in
>> news:1190316521.493308.312510 @k79g2000hse.googlegroups.com:
>>
>>
>>
>> > Hi all,
>> > I have what I hope is a simple question....

>>
>> > I have a table with several columns, the 2 I am concerned with at
>> > the moment are Category and Keywords.

>>
>> > I need to search both of these columns for a word or short phrase
>> > that I get from a form.

>>
>> > For example, the search can be 'Antiques' or 'Antique Dealers'

>>
>> > I tried to use this

>>
>> > SELECT name, address, city, phone
>> > FROM valley
>> > WHERE keywords OR category
>> > LIKE '%$search%'
>> > ORDER BY name LIMIT %d,%d"

>>
>> SELECT name,address,city,phone
>> FROM valley
>> WHERE keywords LIKE '%$search%'
>> OR category LIKE '%$search%'
>> ORDER BY name LIMIT %d,%d

>
> Good Man, Thanks for the reply!
>
> I have a question though..... When I run this query through
> phpMyAdmin, it works fine. However, when I run it through my web site
> I get nada. <!?!>
>
> Any ideas on this?


Not sure really, but I do know that in the past I have had query
problems (particularly when "collation types" were mixed) that worked
perfect at the command line, and failed in PHP..... i'd love to hear
theories about this....

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 11:27 AM
Lars Eighner
 
Posts: n/a
Default Re: Data from 2 columns

In our last episode,
<1190316521.493308.312510@k79g2000hse.googlegroups .com>,
the lovely and talented JimJx
broadcast on comp.databases.mysql:

> Hi all,
> I have what I hope is a simple question....


> I have a table with several columns, the 2 I am concerned with at the
> moment are Category and Keywords.


> I need to search both of these columns for a word or short phrase that
> I get from a form.


> For example, the search can be 'Antiques' or 'Antique Dealers'


> I tried to use this


> SELECT name, address, city, phone
> FROM valley
> WHERE keywords OR category


You can't do that. OR only works with expressions. This isn't English, in
which you can 'or' subjects or predicates.

> LIKE '%$search%'
> ORDER BY name LIMIT %d,%d"


> in several different ways but no joy.


> When I use that snippet of code, I will get any matches from
> 'keywords' but nothing from category, even though I know there is a
> category with the var in it....


> Example:
> If the form passes 'auto' and I have an entry in keywords for 'auto
> dealers' and a category for 'auto repair', I will get the auto
> dealers, but not the auto repair.....


> Any ideas?


> Thanks,
> Jim


--
Lars Eighner <http://larseighner.com/> <http://myspace.com/larseighner>
Countdown: 487 days to go.
What do you do when you're debranded?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 11:27 AM
Paul Lautman
 
Posts: n/a
Default Re: Data from 2 columns

Good Man wrote:
> JimJx <webmaster@valleywebnet.com> wrote in
> news:1190316521.493308.312510 @k79g2000hse.googlegroups.com:
>
>> Hi all,
>> I have what I hope is a simple question....
>>
>> I have a table with several columns, the 2 I am concerned with at the
>> moment are Category and Keywords.
>>
>> I need to search both of these columns for a word or short phrase
>> that I get from a form.
>>
>> For example, the search can be 'Antiques' or 'Antique Dealers'
>>
>> I tried to use this
>>
>> SELECT name, address, city, phone
>> FROM valley
>> WHERE keywords OR category
>> LIKE '%$search%'
>> ORDER BY name LIMIT %d,%d"
>>

>
> SELECT name,address,city,phone
> FROM valley
> WHERE keywords LIKE '%$search%'
> OR category LIKE '%$search%'
> ORDER BY name LIMIT %d,%d


Or:
SELECT name,address,city,phone
FROM valley
WHERE CONCAT_WS(' ',keywords,category) LIKE '%$search%'
ORDER BY name LIMIT %d,%d


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:18 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com