I am upgrading my reptile keeping site. We will soon outgrow what jot and ditto can do. I have everything figured out... so I thought.
let me give you a run down of the tables.
master_ev - holds the event_type, animal_id and date
animals - holds data about the animals, fairly static info
ev_ref - holds event_type and a human readable text
species - similar to above
foodinv - hold type, weight and qty of foodstock
feedings - holds feeding info
notes - holds animal notes
Now the issue I am having is that if the event is a feeding, or a note, I need to pull in the notes, or what exactly they ate. I thought I had a good design, but to get this info I am having to make some insane queries (for me at least) and I can’t figure them out.
Is there a better way to structure the db? I could just add a notes and meal id to every entry, but this creates blank fields and pretty much boils down to what I use now.
Suggestions / ideas?
if you would like me to post the table structures with some play data I can do that.
Thanks!
-
☆ A M B ☆
- 24,524 Posts
No, you’re doing it right. Take a look at the queries in some of the action files in the MODx manager or the document parser itself if you want to see insane queries. Even fetching the TV values for a given document requires some heavy-duty SQL, especially considering that the value for a given document could be the TV’s default value if the one in the document itself is empty.
$sql= "SELECT tv.*, IF(tvc.value!='',tvc.value,tv.default_text) as value ";
$sql .= "FROM " . $this->getFullTableName("site_tmplvars") . " tv ";
$sql .= "INNER JOIN " . $this->getFullTableName("site_tmplvar_templates")." tvtpl ON tvtpl.tmplvarid = tv.id ";
$sql .= "LEFT JOIN " . $this->getFullTableName("site_tmplvar_contentvalues")." tvc ON tvc.tmplvarid=tv.id AND tvc.contentid = '" . $this->documentIdentifier . "' ";
$sql .= "WHERE tvtpl.templateid = '" . $documentObject['template'] . "'";
Yeah I am a lot closer to my goal... just one more thing left figure out.
I had some useless junk in my schema, clearing that out simplified things.
Hey thr
i used following syntax to select external database
$ds = $modx->db->select(’*’,’database_name.table_name’);
but i cant select multiple table at a time. can anybody tell me what i have to do?
Thanks