Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- PHP Dataobject join question
November 24, 2008, 10:27 am
rate this thread
in needCategoryItem called asid, which is FK to needCategory.
I am using pear dataobject and DataGrid to create a data grid view
$dataobject = new DataObjects_NeedCategoryItem();
$datagrid =new Structures_DataGrid(100); /* 10 rows per table */
$IdUrl = "<a href='assessmentAdminForm.php?
$datagrid->addColumn(new Structures_DataGrid_Column('Edit', null,
null, array('width' => '5%'), null, 'printEditLink()'));
$datagridOptions["generate_columns"] = true;
$datagridOptions["fields"] = array ("id", "asid", "title",
"select1", "select2", "select3", "select4");
$datagridOptions["labels"] = array (
"id" => "ID",
"asid" => "Need Category",
"select1" => "Select 1",
"select2" => "Select 2",
"select3" => "Select 3",
"select4" => "Select 4"
needCategoryItem ni inner join needCategory n on ni.asid=n.id order by
/* Pass these options at binding time */
/* Get a reference to the Renderer object */
$renderer =& $datagrid->getRenderer();
/* For the <table> element : */
/* For every odd <tr> elements */
$renderer->setTableOddRowAttributes(array ("class" => "odd"));
/* Get and output HTML links */
$pagingHtml = $renderer->getPaging();
echo "<p>Pages : $pagingHtml</p>";
/* Output */
t works well except that for the column "Need Category", instead of
showing a number (asid), I want to display its corresponding value (in
string) from table needCategory.
I think I need to join two dataobjects.
It does not work
What shall I do so that for the column "Need Category", I can display
its value (by getting its corresponding value from table
Re: PHP Dataobject join question
I'm not familiar with PEAR's DataGrid, but I see what might be a
couple of issues:
1. In your fields and labels arrays, you're referencing the column
"asid", but that column doesn't appear in the query contained by $sql.
2. asid doesn't contain the column that you want, so of course you're
getting the wrong data. The title that you want is (I would guess) in
needCategory.assessname, so you should use that instead. It's already
pulled into the query results by the JOIN.
On a side note, I don't know what "select1", "select2", etc. are, but
it looks like your schema might be violating the first normal form
Charles Calvert | Web-site Design/Development
Celtic Wolf, Inc. | Software Design/Development
http://www.celticwolf.com/ | Data Conversion
(703) 580-0210 | Project Management