Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Streda, 25. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  How to fill a dropdown box with values from multiple tables

phpMyEdit General     How to fill a dropdown box with values from multiple tables
Odoslať novú tému   Odpovedať na tému    
 
Sebzap     Založený: 05.10.2007   Príspevky: 5  
Príspevok Zaslal: 2007-10-05 12:09
Návrat hore  Odpovedať s citátom     

Hello all,

after searching through the forum and the documentation I can't find a solution for doing a join over multiple tables. The solution posted here is not working for the recent version.

Situation: I want to manage the basic function of a library: lend books to people.

The tables I use (with only the important fields to keep it short) are:

tbl_lendings
- id
- book_id

tbl_books
- id
- title
- author_id

tbl_authors
- id
- name

What I want to do is to create a dropdown box in the "add lending" screen where I can select a book. The descritption is supposed to show both the author and the title of the book, e.g. "Simon Singh - The Big Bang".

With the following definition I can show only the book title and the author's ID, but not his name ("1 - The Big Bang").

Kód:

$opts['tb'] = 'tbl_lendings';

$opts['fdd']['book_id'] = array(
  'name'     => 'Book',
  'select'   => 'D',
  'options'  => 'AVCPD',
  'sort'     => true
);
$opts['fdd']['book_id']['values']['table']= 'tbl_books';
$opts['fdd']['book_id']['values']['column']= 'ID';
$opts['fdd']['book_id']['values']['description']['columns']['0'] = 'author_id';
$opts['fdd']['book_id']['values']['description']['divs']['0'] = '-';
$opts['fdd']['book_id']['values']['description']['columns']['1'] = 'title';


How can I accomplish what I want to do? Is the magic word "virtual fields"? Or is there another solution?

Thanks in advance for any reply!

Regards
Sebastian

 
michal     Založený: 17.06.2003   Príspevky: 537   Bydlisko: Slovakia
Príspevok Zaslal: 2007-10-05 12:22
Návrat hore  Odpovedať s citátom     

with current pme i see two solutions:
- create a view author_book
- in pme config something like
$opts['fdd']['dummy']'values2'] = array( 'table'=>'tbl_authors', 'column'=>'id', 'join'=>'tbl_book.author_id = tbl_author.id');

or something similar (create dummy field with all authors in, an in join part limit them to the book), i've never tested it.

btw, each book has just one author ? :)

 
Sebzap     Založený: 05.10.2007   Príspevky: 5  
Príspevok Zaslal: 2007-10-05 12:27
Návrat hore  Odpovedať s citátom     

Thanks for the quick reply! Actually I'm not managing a library but a more specific application. I thought it's more easy for others to understand the problem if I use a more common example. You are right - the database scheme is not the best... :-)
I will try to get it work and come back to you.

 
Sebzap     Založený: 05.10.2007   Príspevky: 5  
Príspevok Zaslal: 2007-10-05 13:21
Návrat hore  Odpovedať s citátom     

Sorry, I do not get any step close... I'm thinking about triggers, the php directive, ... My head is stuck.
May you give me a little bit more code?
What do you mean with "create a view author_books"?
Are triggers or the php directive an option?

 
michal     Založený: 17.06.2003   Príspevky: 537   Bydlisko: Slovakia
Príspevok Zaslal: 2007-10-06 13:28
Návrat hore  Odpovedať s citátom     

on the sql level, create a view (see man create view) that will include all necessary fields in one table/view.

 
Sebzap     Založený: 05.10.2007   Príspevky: 5  
Príspevok Zaslal: 2007-10-09 12:16
Návrat hore  Odpovedať s citátom     

Okay, I thought you mean a view within PME. I created the view on the MySQL level and it works like a charme. Would have preferred to do this within PME but that is good enough. Thanks Michal!

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov