DarkLord7854
Založený: 20.01.2010
Príspevky: 1
Zaslal: 2010-01-20 18:41
Návrat hore
Odpovedať s citátom
|
So I've read a bunch of threads and their examples, and I tried adapting it to my code, but while it doesn't error or anything, it just doesn't seem to do anything.
I have 1 table I need to join, and I really just need 1 column to be joined.
Main Table: iin_listings
id
member_id
zone
cat_id
Join table: iin_categories
cat_id
cat_name
I just want to join the categories to the listings and replace the cat_id (since it's a number) with the cat_name (category description).
So instead of showing records with IDs, it shows them with the category name, e.g. "General" instead of "1".
Code I've tried to use:
| Kód: |
$main_table = 'iin_listings'; // alias of the main table
$join_table = 'iin_categories'; // alias of the values table
$join_column = 'cat_id'; // join column in the values table
$join_description = 'cat_name'; // description column in the values table
$main_column = 'cat_id'; // join column in the main table
$opts['fdd']['cat_id']['values']['join'] = '$main_table.$main_column = $join_table.$join_column';
$opts['fdd']['cat_id']['values']['table']='iin_categories';
$opts['fdd']['cat_id']['values']['column']='cat_id';
$opts['fdd']['cat_id']['values']['description'] = 'cat_name';
|
I also tried:
| Kód: |
$join_table = 'iin_listings'; // alias of the values table
$main_table = 'iin_categories'; // alias of the main table
$join_column = 'cat_id';
$join_description = 'cat_name';
$main_column = 'cat_id';
$opts['fdd']['cat_id'] = array(
'default' => '',
'input' => '',
'maxlen' => 30,
'name' => 'Category Name',
'options' => 'ACPVD',
'required' => false,
'select' => '',
'size|ACP' => 30,
'sqlw' => 'TRIM("$val_as")',
'sort' => true,
'values' => array(
'join' => '$main_table.$main_column = $join_table.$join_column',
'table' => 'iin_listings',
'column' => 'cat_id',
'description' => array(
'columns' => array($join_description)
)
// , 'filters' => 'category = "Client"'
)
);
|
But the list of record is still the same, showing the category ID instead of it's name from the category table.
Ideally I'd also need to change the category ID field when editing a record to have a dropdown menu from the category name table as well, but I never got that far since I can't even get them to show on the main list page.
Any help would be appreciated.
Here's a link to the full code (minus database connection info obviously..):
http://tech-burrow.com/phpmyedit/query.txt
Thanks in advance
|
doug
Založený: 10.02.2003
Príspevky: 1013
Bydlisko: Denver, Colorado (USA)
Zaslal: 2010-01-23 15:52
Návrat hore
Odpovedať s citátom
|
I don't need JOIN very often. I believe the following is a working example from one of my scripts. Perhaps if you compare this with your script then you will find the correct solution.
| Kód: |
$main_table = 'domain'; // alias of the main table
$join_table = 'contacts'; // alias of the values table
$join_column = 'contact_id'; // join column in the values table
$join_description = 'company'; // description column in the values table
$main_column = 'domain_id'; // join column in the main table
$opts['fdd']['registrar'] = array(
'default' => '',
'input' => '',
'maxlen' => 30,
'name' => 'Registrar',
'options' => 'ACPVDFL',
'required' => false,
'select' => '',
'size|ACP' => 30,
'sqlw' => 'TRIM("$val_as")',
'sort' => true,
'values' => array(
'join' => '$main_table.$main_column = $join_table.$join_column',
'table' => 'contacts',
'column' => 'contact_id',
'description' => array(
'columns' => array($join_description)
)
// , 'filters' => 'category = "Registrar"'
)
);
// MySQL column 8: string - varchar(30)
// Join table and main table remain unchanged from the above usage
// Different main column, join column and join description are used for 'owner_id' below
$join_column = 'display_name';
$join_description = 'display_name';
$main_column = 'owner_id';
$opts['fdd']['owner_id'] = array(
'default' => '0',
'input' => '',
'maxlen' => 5,
'name' => 'Owner Id',
'options' => 'ACPVDFL',
'required' => false,
'select' => '',
'size|ACP' => 5,
'sqlw' => 'TRIM("$val_as")',
'sort' => true,
'values' => array(
'join' => '$main_table.$main_column = $join_table.$join_column',
'table' => 'contacts',
'column' => 'contact_id',
'description' => array(
'columns' => array($join_description)
)
// , 'filters' => 'category = "Client"'
)
);
// MySQL column 30: int - smallint(5) unsigned |
|
|
Odoslať novú tému
Odpovedať na tému
|
|