Jump to content


Photo

Filtering MySQL entries by two variables


  • Please log in to reply
5 replies to this topic

#1 SephirGaine

SephirGaine
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 21 September 2006 - 07:28 PM

Hola. Just a quick question, should be easy to answer, and needless to say I feel real amateur not knowing the answer. However, I want to echo all data entries from a DB table, however I want to be able to filter through using two variables. One is easy enough, simply use SELECT X from Table WHERE Y=Z. But, I want to use two WHERE variables in the same string. What's the proper way to do so?

And if it's actually needed, I need to select these from a certain year, and whether or not they're open tickets at the time. So, for this mini-project, "Date" and "Dead" are going to be my two variables I want to filter through.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 21 September 2006 - 07:34 PM

SELECT ..... WHERE YEAR(date) = '$theYear' AND Dead = '$deadValue'
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 SephirGaine

SephirGaine
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 21 September 2006 - 07:37 PM

Coo'. Easy enough, thanks.

#4 SephirGaine

SephirGaine
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 21 September 2006 - 08:33 PM

One more quick question. Having trouble displaying the entries now, narrowed it down to something in my mysql query. I've looked over it too many times to count and I'm not too sure what's wrong, however.

"SELECT * FROM Leads where Date='$LeadYear2' AND Dead=0 ORDER BY '$LeadSort' ASC"


#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 21 September 2006 - 09:15 PM

Define "having trouble".

We have no idea what is in your table or what is in your variables or what it is doing that shouldn't be doing or what it's not doing that it should.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 SephirGaine

SephirGaine
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 21 September 2006 - 09:21 PM

Ah, disregard that, sorry. Got it figured out. What was happening, however, was that when I took out "where Date='$LeadYear2' AND Dead=0 ORDER BY '$LeadSort' ASC"" it would display all the results within that table like it should, and as soon as I placed the rest of the query back in and tried, nothing would show. It was basically just a stupid mistake on my own part, however. Thanks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users