473,774 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DB_DataObject Complex joins

I have a query where I need to join several tables, one of which is
variable (otherwise I'd just hand-code the query). The main table is
called media, and has fields common to all media in my application
(like project_id, description, comments, etc). I have another couple of
tables, one provides a listing of keywords, and another maps keywords
to media.

I want to enable a search of media by keyword, allowing for multiple
keywords. For a query where ANY of the terms (OR) is acceptable, the
following code snippet works just fine:

$keyword = DB_DataObject:: factory('keywor d');
foreach ($terms as $term) {
$term = trim($term);
// $data['values']['searchPage']['whereAdd'] is either OR or AND
$keyword->whereAdd("keyw ord.term LIKE '%" . $keyword->escape($term ) .
"%'", $data['values']['searchPage']['whereAdd'] );
}

// Add the Joins
$media_has_keyw ord = DB_DataObject:: factory('media_ has_keyword');
$media_has_keyw ord->joinAdd($keywo rd);
$media->joinAdd($media _has_keyword);

This will not work when $data['values']['searchPage']['whereAdd'] =
'AND', because one keyword.term can never be like A and like B at the
same time (unless A == B).

One way I thought about getting around this was creating a new $keyword
object for each search term, and LEFT or RIGHT joining them to one
$media_has_keyw ord. This did not work, but maybe I did not implement
it correctly.

Any one have any thoughts on how I can use DB_DataObjects to require
the media to have a mapping with ALL the keywords a user might specify?

Sep 21 '05 #1
0 1326

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1549
by: Vijay | last post by:
Hello friends, I have a problem with one of the JOIN query here. Below is a brief description of the problem. tablename : test RecordId EffectiveDate othertableid value -------- ------------- ------------ ----- 1 2004-01-10 1 10
2
1467
by: David Richards | last post by:
Hi, I'm having a problem linking 4 tables in MYSQL. The first table contains customer details, the next item details and the next 2 contain sales information. The final output of the query should be:-
8
5066
by: Matt | last post by:
Hi all, Thank you for taking the time. I have a database with 45 tables on it. 44 tables are linked to a main table through a one to one relationship. My question is, is there no way i can have a query that will pull a single field from all the tables. In other words i should have 44 fields. when i try to do that same, i get an error message saying "Query is too complex"
9
2052
by: jardar.maatje | last post by:
I am logging scientific data. For this a normal relationship database is not idéal but I am going to try it. I have basically three tables like: datarecord: * idx - integer * time - datetime * type - integer
1
1492
by: hel | last post by:
Hi I have just adopted a PHP project and need some help understanding DB_DataObject. I've looked around on the web and can't find a simple explanation. Basically, my MySQL database has no tables. I have a createTable.php script which I believe is a standard script, it runs but tell me "NO TABLES". There is a function in the script called _createTableList() which is looking for tables not finding any (I don't really
0
1671
by: Tom | last post by:
I'm using the DB_DataObject script createTables.php to auto-generate the necessary database schema on two databases. Using the .ini approach (not the in-line PHP approach) to configure DB_DataObject in my script. Everything is by the book, but I'm having a big problem: Here's my main.ini file: database_one = mysql://user:password@localhost/one database_two = mysql://user:password@localhost/one
1
2174
by: mmr315 | last post by:
pl help me how to use DB_DataObject database abstraction layer class in php
2
2315
by: Sam | last post by:
Recently started using DB_DataObject with a Postgresql DB. Seems pretty nice, but I am not sure if insert() is supposed to be able to return the id of a recently returned object. It just seems to return 1 for me. I'm not really sure if DataObject gets confused because it would like to create the sequences itself which have been created for me automatically because I created the primary keys as serials. Or something like that. Would at...
36
2497
by: TC | last post by:
I've used Access for many years. Several times, I've encountered a bug which I refer to as the "Vanishing Joins" bug. When it happens, joins vanish randomly from queries. More specifically, all joins vanish from at least one (seemingly random) query. I've always regarded the Vanishing Joins bug as a symptom of corruption. When it happens, I usually give my users advice on how to recover from corruption, and how to avoid it in the future....
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9915
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4014
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.