Search
Left Quote    Choose a job you love, and you will never have to work a day in your life.
- Confucius    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: Get sql results from previous sql
  This user is offline  Genius
  Subject: "Get sql results from previous sql" Posted: @ 12:18 am on Dec 01 2008   

Member #: 582
Rank: User - (77)
Since: 02/18/08
Posts: 76
From: kmmk

Ok, I had a problem with my mysql query:


SELECT * FROM `mp3` WHERE `title` LIKE '%".$query ."%' OR `song_author` LIKE '".$query. "' OR `album` LIKE '".$query. "' AND `active` > '0' ORDER BY `song_author`, `title` ASC

This query even shows mp3s that are 0. I even tried `active` = '1' when some of the songs were active = 1 but it still showed all. So can somebody correct this sql? I think AND and OR cannot be in same query?

Then I thought of an idea to have two sql statements. One will get all active mp3's while other get all songs that match the query from the first query. Don't have clue if its possible or what function to use.

P.S: I tried using UNION, just displayed every song in the db. Therefore I don't think thats the function to use.


    Viewed: 5,358 Times | Reply to This | To top
  This user is offline  David1159
  Subject: "re: Get sql results from previous s..." Posted: @ 7:24 pm on Dec 01 2008    

Member #: 526
Rank: User - (81)
Since: 12/27/07
Posts: 81
From: usa

I believe the issue is the AND operator.

You need parenthesis through out there.

Example-
SELECT * FROM Persons WHERE
LastName='Sven dson' AND (FirstName='To ve' OR FirstName='Ola ')




Coding is simply CST... Combining $hit Together. We make different $hit to run in unison correctly.

    Viewed: 5,346 Times | Reply to This | To top
  This user is offline  misterhaan
  Subject: "re: Get sql results from previous s..." Posted: @ 7:37 pm on Dec 01 2008    

Member #: 5
Rank: User - (213)
Since: 02/11/05
Posts: 148
From: chair

right




please note that the above post is likely made up in its entirety.

    Viewed: 5,341 Times | Reply to This | To top
  This user is offline  Genius
  Subject: "re: Get sql results from previous s..." Posted: @ 8:58 pm on Dec 01 2008    

Member #: 582
Rank: User - (77)
Since: 02/18/08
Posts: 76
From: kmmk

Thanks a lot, David1159 and misterhaan. That was the problem.

This query fixed the issue:

SELECT * FROM `mp3` WHERE (`title` LIKE '%".$que ry."%' OR `song_author` LIKE '".$quer y."' OR `album` LIKE '".$quer y."') AND (`active` > '0') ORDER BY `song_author`, `title` ASC



Edited at 09:08:09 pm on 12/01/08


    Viewed: 5,336 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank