#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    7
    Rep Power
    0
    Here's the skinny... i am a relative newcomer to PHP but have managed to do some wonderful things with it. But i've hit a stumbling block:

    I have a query that returns a single record from a table and the info is displayed nicely in a HTML page. At the bottom of this page i would like to provide links to relevant pages for this particular record. Specifically, the page is showing a particular music CD and i want to show other CDs available by that artist at the bottom of the page.

    Can i write a second SELECT statement that uses my resulting artist field as part of its WHERE clause? My attempts so far have failed.

    Please help.
  2. #2
  3. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    sure, just throw the variable in the WHERE
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Indonesia
    Posts
    87
    Rep Power
    15
    sure you can do it !!!

    example :

    your artist is stored in $artist.
    Then you can issue this query :
    $query = "select * from tablename where artist = '$artist'";

    That's it !!

    See ya

    ------------------
    CyberOsc
    sphmjf_oscario@gurlmail.com

    ** It's the world of Oscario **
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    7
    Rep Power
    0
    Thanks for the help guys... but... i'm still not getting the result i want.

    The following query lists the entire catalog at the bottom of the page:

    select * from master where artist like '%$artist%'

    ...and this one shows no results:

    The second query doesn't seem to want to accept the value $artist obtained from the first query as part of its criteria.

    Any more suggestions....

  8. #5
  9. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,646
    Rep Power
    4492
    Are you sure $artist is being set correctly? If it's not, you query will end up:

    select * from table where '%%'

    which will give you everything. You shouldn't even need the percent signs.

    ---John Holmes...
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    7
    Rep Power
    0
    I actually was able to get it after tinkering for an hour. I had to use the array(?) from the previous query to get it out. Maybe the code will help explain:

    select * from master where artist like '%$myrow[artist]%'

    I actually had to use the wildcards (%) too...

    Thanks for everyone's help... you guys are fast!
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    London/UK
    Posts
    91
    Rep Power
    15
    FWIW
    If you've only got a few hundred records then a query like that is fine (once you've ironed out your problems), but if you plan on using that query on > n thousand records then you'll start noticing major database performance issues. A %wildcard% WHERE has to do a regexp on every record. Try running queries where you'll be matching - for example - WHERE whatever LIKE 'thing%'. One way to do this is to create a lookup table of unique words.

    I only say this as I had a rude awakening recently when I started running queries like that on > 1 million records....15 minutes later.....

    Bealers

    ------------------
    http://back-end.org
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    7
    Rep Power
    0
    Thanks for the tip.

Similar Threads

  1. Build HTML tables with multiple mySQL queries
    By SailFan in forum PHP Development
    Replies: 5
    Last Post: January 19th, 2004, 12:25 PM
  2. putting multiple queries into one query, can it be done
    By sapien in forum PHP Development
    Replies: 3
    Last Post: September 30th, 2003, 04:03 PM
  3. multiple queries using php
    By h3r2on in forum MySQL Help
    Replies: 3
    Last Post: August 8th, 2003, 12:31 PM
  4. multiple queries
    By gordonc in forum PostgreSQL Help
    Replies: 0
    Last Post: July 21st, 2003, 12:43 PM
  5. multiple select box search queries
    By ravinder in forum PHP Development
    Replies: 0
    Last Post: July 8th, 2003, 12:50 PM

IMN logo majestic logo threadwatch logo seochat tools logo