It is currently Sat Feb 04, 2012 3:37 pm

All times are UTC + 2 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: filtering select query to produce drop down list
PostPosted: Mon Oct 15, 2007 12:35 am 
Offline

Joined: Mon Oct 15, 2007 12:22 am
Posts: 6
Hi, am a relative newbie to php & mysql and am having a huge problem with one piece of code in my joomla site.
I have the following code:

$query = "SELECT #__listings2_cat_items_relations.catid,#__listings2_cat_items_relations.itemid,#__listings2_cats_relations.catid,#__listings2_cats_relations.parentid,#__listings2_item.itemid#__listings2_item.title FROM #__listings2_cat_items_relations LEFT JOIN catid ON #__listings2_cat_items_relations.catid = #__listings2_cats_relations.catid AND JOIN itemid ON #__listings2_cat_items_relations.itemid = #__listings2_item.itemid WHERE #__listings2_cats_relations.parentid = '3'";
$database->setQuery( $query );
//$parent_id = '#__listings2_cats_relations.parentid';
$cat_id = $database;
$title = $this->title;

if ($cat_id = 3) {
$statement = "INSERT INTO jos_jcalpro_venues (venue_id,venue_name,venue_link,color,bgcolor,options,level,published,checked_out,checked_out_time) VALUES ('', '$title', '', 'default', 'default', 0, 0, 1, 0, '0000-00-00 00:00:00')";
$database->setQuery($statement);
$database->query();
if ($database->getErrorNum())
$config->logSobiError('saveSobi():'.$database->stderr());
}

What is comes from is this...
I have one piece of the site where people can create directory listings, and another where people can list events in a calendar. What I need is for the listings entered for venues to appear as choices available for where the events can take place. The code above puts the right information from the listings into the new table called 'venues' in the calendar part of the database. Unfortunately it is inserting data on ALL the listings created, not just the venues. The venues all belong to categories that have a parent category 'venues' which is the id '3' in the code above. I know there is something seriously wrong with the way in which I'm filtering / sub-selecting the right records - can anyone help?
I've tried googling and searching a number of forums, but must not be searching for the right thing!
Thanks
Ali


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 16, 2007 4:15 am 
Offline

Joined: Sun May 02, 2004 11:34 pm
Posts: 6498
Location: toronto, canada
You were missing a comma in the statement (unless its a copy'n'paste error, otherwise I only removed the AND between the JOINS...

Code:
$query = "SELECT
             #__listings2_cat_items_relations.catid,
             #__listings2_cat_items_relations.itemid,
             #__listings2_cats_relations.catid,
             #__listings2_cats_relations.parentid,
             #__listings2_item.itemid,              //missing comma here
             #__listings2_item.title
           FROM
             #__listings2_cat_items_relations
           LEFT JOIN
             catid
           ON #__listings2_cat_items_relations.catid = #__listings2_cats_relations.catid
           JOIN
             itemid
           ON
             #__listings2_cat_items_relations.itemid = #__listings2_item.itemid
           WHERE
             #__listings2_cats_relations.parentid = '3'";



_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 16, 2007 4:32 pm 
Offline

Joined: Mon Oct 15, 2007 12:22 am
Posts: 6
Thanks very much, that helps loads - can't believe I missed that.
I've realised there's a problem in the if statement in the second part of the code though - am working out how to compare the itemid from the current feature to the itemid fields in the query results. Any help appreciated! Will keep trawling google and forums til I figure it out though


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 2 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron