PHP forums, MySQL forums, Web Development resources

Home PageHome    PHP ResourcesTopic List    FAQFAQ    SearchSearch    MemberlistMemberlist    UsergroupsUsergroups 
 RegisterRegister
    ProfileProfile    Log in to check your private messagesLog in to check your private messages    Download the RSS Reader RSS Feed Download the RSS Reader RSS for this forum Log inLog in 

PHP Forum :: MySQL Forum :: Java Script Forum



filtering select query to produce drop down list

 
Post new topic   Reply to topic    WeberForums.com Forum Index -> PHP General
View previous topic :: View next topic  
Author Message
walkerweb



Joined: 14 Oct 2007
Posts: 6

PostPosted: Sun Oct 14, 2007 11:35 pm    Post subject: filtering select query to produce drop down list Reply with quote

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
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 6033
Location: toronto, canada

PostPosted: Tue Oct 16, 2007 3:15 am    Post subject: Reply with quote

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'";


Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
walkerweb



Joined: 14 Oct 2007
Posts: 6

PostPosted: Tue Oct 16, 2007 3:32 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
WeberTrivia Questions WeberTrivia Questions
 Think you are smart? Prove it!. Try your skills with these questions :
 WeberTrivia QuestionsRecursive arrays and multi-dimensional arrays are one and the same. (PHP and MySQL)
 WeberTrivia QuestionsThe \"cache_dir\" tag of the squid configuration has a default of /var/spool/squid. (Linux)

WeberTrivia Questions



PHP Code Examples
 Stream diffrent sizes of images from a single image to save disk space.
 JavaScript dropdown list menu to switch any page.
 Dump the contents of a PHP variable in html format with a recursive list of subfolders and files from a given root directory.
 PHP Dump in html format the contents of one array variable with a recursive list of the nested array variables inside.
 Link Extractor - This function is used to extract links from a given URL. This will convert relative path into absolute path and also remove PHPSESSID stuff.
 Building a Dynamic Form using Javascript and innerHTML. Add form elements in realtime without refreshing the page.
 A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function.
Post new topic   Reply to topic    WeberForums.com Forum Index -> PHP General All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
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




Powered by phpBB © 2001, 2005 phpBB Group
PHP Forum :: MySQL Forum :: Java Script Forum