Two MySQL Questions.
Date: 09/05/07
(PHP Community) Keywords: mysql, sql
1.) I'm trying to build a Query where you have condition 1 which is absolute (like foo = 'Bar') but then condition 2 which could have several options. This is how it looks:
WHERE company_name = 'FOO' && entered_by = 'BOB' || entered_by = 'JOE' || entered_by = 'KAT'
What it is 'supposed' to do is pull up any records with company name of FOO that were entered by BOB, JOE, or KAT. But instead it's just pulling up all records entered regardless of the company_name restriction. What am I doing wrong here?
2.) Some of the company names use a & symbol which is wreaking havoc on the query. I've tried to use mysql_real_escape_string and addslashes but neither solve the problem; leaving a company name like R&F Cola reduced to a query search of R. How do I get MySQL to accept that the & is just part of the query?
Thank you so much to anyone who helps. I'm sure I"m missing something easy; but those are usually the most annoying ones!
Source: http://community.livejournal.com/php/583537.html