Current location: Hot Scripts Forums » Programming Languages » PHP » Trouble with query


Trouble with query

Reply
  #1 (permalink)  
Old 12-16-03, 01:23 PM
coolblu coolblu is offline
Newbie Coder
 
Join Date: Dec 2003
Location: UK
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Trouble with query

Hi all. I'm new here so I thought I would start off with a request for some PHP and mySQL help

I am having a bit of trouble selecting information from a database I have created in MySQL. The database is for a web site that will reference a music collection.

So far I am using the following query, which selects the information I need:

PHP Code:

$query 'SELECT * FROM records LEFT JOIN labels ON (records.label = labels.labelid) ORDER BY artistname ASC'
Here I have the tables "records" and "labels", which hold the details of the music and the label they were recorded on respectively. This function is being used to output all of the data in the database.

From this query I am then using a while loop to extract information:

PHP Code:

    while ($rowmysql_fetch_array($query)) {

        
$getID $row["id"];
        
$title $row["title"];
        
$artistname $row["artistname"];
        
$description $row["description"];
        
$price $row["price"];
        
$labelname $row["labelname"];


print <<<END
$count.) $title by $artistname ($labelname)
END;
echo 
"\n";
        echo 
"<b>$description</b>\n<br><br>\n";
        echo 
"Now only <font color=red>$price</font>\n\n<br><br>";
        
$count++ ;
    } 
So far this gets all of the data I need.

However the problem arises when I want to get the condition of the record (literally record as in vinyl ) from a table called "condition". Here there are a number of conditions, given a "conditionid" (unique) and a "abbr" (abbreviation) e.g. Mint condition is referenced as conditionid "1" and abbr "M".

I think the problem lies in the fact that each record in the "records" table has two condition ratings (an integer which links to the conditionid in the condition table). These values are "rcon" (The condition of the record) and "scon" (The condition of the sleeve of the record e.g. its cover). In effect these could be either the same (both the record and the sleeve are in the same condition) or could be different (the condition of the sleeve is not the same as the record).

I thought that the following query would be valid:

PHP Code:

$query 'SELECT * FROM records

LEFT JOIN labels AS labels ON ( records.label = labels.labelid ) 
LEFT JOIN condition AS recordcondition ON ( records.id = recordcondition.conditionid ) 
LEFT JOIN condition AS sleevecondition ON ( records.id = sleevecondition.conditionid ) 
ORDER BY artistname ASC' 
However I cant seem to get the correct information out of the database using a while loop (I think maybe I need to perform the query some other way to do so).

If you have got this far down the page thanks for reading about my problem If you have any ideas about how I can solve this or need a better explanation (I can try ) please reply below.


Thanks

'blu
Reply With Quote
  #2 (permalink)  
Old 12-17-03, 12:47 AM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

What is your database structure? It looks like there is one-to-many relationship between `records` (one) and `recordcondition` (many), and the same for `records` (one) and `sleevecondition` (many).

If these condition tables hold values like 'Mint' or some sort like you said, shouldn't these relationship be the other way around?

You have record's ID matching condition's ID, but there should be condition fields in records table that store each condition ID.

If you can post your table definition, I may be able to help you further.
__________________
Blavv =|
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM
Syntax error (missing operator) in query expression crobinson ASP 4 11-23-03 08:49 PM
Show query results by in a different way mdhall PHP 4 11-09-03 11:18 AM
creating calculated fields in mysql resource after query Abu Mami PHP 0 07-31-03 06:47 AM


All times are GMT -5. The time now is 07:34 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.