PHP Dataobject join question

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have two tables, needCategory and needCategoryItem. There is a field
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"

n.assessname,n.title,n.select1,n.select2,n.select3,n.select4 from
needCategoryItem ni inner join needCategory n on order by";

        /* Pass these options at binding time */
    $datagrid->bind($dataobject, $datagridOptions);

    /* Get a reference to the Renderer object */
    $renderer =& $datagrid->getRenderer();

    /* For the <table> element : */
    $renderer->setTableAttribute("class", "general");

    /* 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.

I do:

$dataobject_needCategory=new DataObjects_NeedCategory();


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
needCategory) ?


Re: PHP Dataobject join question

wrote in

Quoted text here. Click to load it

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
< .

[snip rest]
Charles Calvert             |  Web-site Design/Development
Celtic Wolf, Inc.           |  Software Design/Development |  Data Conversion
(703) 580-0210              |  Project Management

Site Timeline