September 13th, 2000, 07:59 PM
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.
September 13th, 2000, 10:13 PM
sure, just throw the variable in the WHERE
September 14th, 2000, 02:08 AM
sure you can do it !!!
your artist is stored in $artist.
Then you can issue this query :
$query = "select * from tablename where artist = '$artist'";
That's it !!
** It's the world of Oscario **
September 14th, 2000, 04:54 PM
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....
September 14th, 2000, 05:39 PM
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.
September 14th, 2000, 05:52 PM
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!
September 14th, 2000, 05:57 PM
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.....
September 18th, 2000, 05:13 PM