Posted: Sun Oct 14, 2007 11:35 pm Post subject: filtering select query to produce drop down list
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
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
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 You cannot vote in polls in this forum