Skip to main content
July 14, 2007
Answered

hi using php but having problem with search results

  • July 14, 2007
  • 6 replies
  • 415 views
Hi my search results are working except for a very important part of only showing those that are active, set by admin.
It is showing results event if they are inactive.
My default in mysql is set to inactive and in edit I change to active.
This is what my search is:
This topic has been closed for replies.
Correct answer Newsgroup_User
jjjhbj111 wrote:
> Hi my search results are working except for a very important part of only
> showing those that are active, set by admin.
> It is showing results event if they are inactive.

Rewrite the WHERE clause like this:

WHERE listingf.status = 'active' AND
(listingf.classbusinessname LIKE '%SearchString%'
OR listingf.inv_addr1 LIKE '%SearchString%'
OR listingf.classcatid LIKE '%SearchString%'
OR listingf.categorytype LIKE '%SearchString%'
OR listingf.inv_state LIKE '%SearchString%'
OR listingf.inv_addr2 LIKE '%SearchString%'
OR listingf.tel LIKE '%SearchString%')

Notice that the section after AND is enclosed in parentheses.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

6 replies

July 27, 2007
thanks I thought so...
Inspiring
July 27, 2007
jjjhbj111 wrote:
> What I mean is the inv_state is a foreign key but I am wanting to show the
> inv_statename.

To do that, you need to list all the columns that you want to retrieve
instead of using *. Then add inv_statename and the the name of the table
that it resides in.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
July 27, 2007
Hi just a quick question even though this is solved.
With the results page I am wanting to show the actual name instead of the foreign key.
What I mean is the inv_state is a foreign key but I am wanting to show the inv_statename.
I am wondering your thoughts as to keep the query the same include the inv_state table.
Thanks very much for your advice here it has been great...
Inspiring
July 15, 2007
jjjhbj111 wrote:
> Thank you so much David, you are sooo cool!
> Switching around sometimes I forget to try that. I was starting to think of
> really complex recordsets.

Glad to have sorted it so quickly. Sometimes, the simple solution is all
you need, but it often takes another pair of eyes to spot it.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
July 14, 2007
Thank you so much David, you are sooo cool!
Switching around sometimes I forget to try that. I was starting to think of really complex recordsets. Y ou have saved me writing a whole lot of gibberish.
I did have the parenthesis in the beginning when I was using an inner join but removed it when I thought I didn't need it.
Something more to learn about.
Thanks again!!
Newsgroup_UserCorrect answer
Inspiring
July 14, 2007
jjjhbj111 wrote:
> Hi my search results are working except for a very important part of only
> showing those that are active, set by admin.
> It is showing results event if they are inactive.

Rewrite the WHERE clause like this:

WHERE listingf.status = 'active' AND
(listingf.classbusinessname LIKE '%SearchString%'
OR listingf.inv_addr1 LIKE '%SearchString%'
OR listingf.classcatid LIKE '%SearchString%'
OR listingf.categorytype LIKE '%SearchString%'
OR listingf.inv_state LIKE '%SearchString%'
OR listingf.inv_addr2 LIKE '%SearchString%'
OR listingf.tel LIKE '%SearchString%')

Notice that the section after AND is enclosed in parentheses.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/