Display multiple tables on same page, from same database table

40 views
Skip to first unread message

Monil

unread,
Apr 11, 2011, 9:08:32 PM4/11/11
to TableGear
I need to generate multiple tables / grids from a single database
table on the same page.

I tried to use the suggestions from http://andrewplummer.com/code/tablegear/example17.html
(but, for the same table). The first table shows up correctly.
However, the following tables on the same page show up with check
boxes and "update" button.

I am not sure what I am missing to display multiple grids, from the
same table.

Any help is appreciated.

Many thanks in advance for your help and an excellent product.

Andrew

unread,
Apr 14, 2011, 8:21:10 AM4/14/11
to TableGear
I tried it out and everything worked for me...
Look through the code again and make sure you're keeping all the
variables separate.
Specifically, you should look at the options and table instance... so:

$options1 = array(...);
$options2 = array(...);

$table1 = new TableGear($options1);
$table2 = new TableGear($options2);

// then later...

$table1->getTable();
$table2->getTable();


It seems like you might be doing something wacky like sharing the
options hash, or maybe calling getTable on the same instance twice...
Keep everything separated and you should be OK.





On Apr 12, 10:08 am, Monil <moni...@gmail.com> wrote:
> I need to generate multiple tables / grids from a single database
> table on the same page.
>
> I tried to use the suggestions fromhttp://andrewplummer.com/code/tablegear/example17.html

Monil

unread,
Apr 17, 2011, 4:18:40 PM4/17/11
to TableGear
Is it possible to share a working example?

May be I am doing something wrong.

Currently, I do have $options1 = array(), $options2 = array() ;
> $table1 = new TableGear($options1);
> $table2 = new TableGear($options2);
>
> // then later...
>
> $table1->getTable();
> $table2->getTable();

But, I see one table (first) show up correctly, second one with
CheckBoxes.

-Monil C

Monil Chheda

unread,
Apr 17, 2011, 4:36:50 PM4/17/11
to TableGear
Here is what I have.

----------
<include all files>

$options='option';
$gridcnt=2;

$table = sample';

        ${$options.$gridcnt}["editable"]  = array("status");

        ${$table.$gridcnt} = new TableGear(${$options.$gridcnt});

        ${$table.$gridcnt}->fetchData($query);


  <div>
    <?php echo ${$table.$gridcnt}->getTable() ?>
  </div>
<?php echo ${$table.$gridcnt}->getJavascript("jquery") ?>

--------------

I do notice that the output HTML has <table id="tgTable"> for all tables. How can we update it? may be that is what is causing a problem.

Any help is appreciated.

Best Regards,
Monil Chheda

Monil

unread,
Apr 17, 2011, 8:47:54 PM4/17/11
to TableGear
Just to make sure we all are on same page...

I am using this to call the SAME DB table... I am not trying to show
data from two separate tables.

So, probably, passing the a custom table ID may help.

-Moni C

On Apr 17, 4:36 pm, Monil Chheda <moni...@gmail.com> wrote:
> Here is what I have.
>
> ----------
> <include all files>
>
> $options='option';
> $gridcnt=2;
>
> $table = sample';
>
>         ${$options.$gridcnt}["editable"]  = array("status");
>
>         ${$table.$gridcnt} = new TableGear(${$options.$gridcnt});
>
>         ${$table.$gridcnt}->fetchData($query);
>
>   <div>
>     <?php echo ${$table.$gridcnt}->getTable() ?>
>   </div>
> <?php echo ${$table.$gridcnt}->getJavascript("jquery") ?>
>
> --------------
>
> I do notice that the output HTML has <table id="tgTable"> for all tables.
> How can we update it? may be that is what is causing a problem.
>
> Any help is appreciated.
>
> Best Regards,
> Monil Chheda
>

Andrew

unread,
Apr 17, 2011, 9:39:11 PM4/17/11
to TableGear
Hm ok... well here's an example of the code that's working for me
below...
Tablegear should be handling the IDs directly... The second table
should increment to 2, then 3, etc.




<?php

include("../lib/include/tablegear.php");
include("../config.php");

$options = array();
$options["database"] = array();
$options["pagination"] = array();



$options["database"]["name"] = DATABASE_NAME;
$options["database"]["username"] = DATABASE_USER;
$options["database"]["password"] = DATABASE_PASS;
$options["database"]["table"] = "labs_tablegear2";
$options["database"]["utf8"] = true;

$options["allowDelete"] = true;
$options["editable"] = "all";
$options["showAddNewRow"] = true;


$options["pagination"]["perPage"] = 10; // 10 rows per page.
$options["pagination"]["prev"] = "prev"; // "prev" link will be
shown.
$options["pagination"]["next"] = "next"; // "next" link will be
shown.
$options["pagination"]["linkCount"] = 2; // 2 links on each side of
the current page.
$options["pagination"]["first"] = true; // Show "first" link.
$options["pagination"]["last"] = true; // Show "last" link.

$options["transform"] = array(
'field4' => array('tag' => 'span', 'html' => '{ASSOCIATED}',
associate => 'field2')
);

$table = new TableGear($options);


$o2 = array();
$o2["database"] = array();
$o2["database"]["name"] = DATABASE_NAME;
$o2["database"]["username"] = DATABASE_USER;
$o2["database"]["password"] = DATABASE_PASS;
$o2["database"]["table"] = "labs_tablegear";
$o2["database"]["utf8"] = true;



$t2 = new TableGear($o2);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
>
<title>TableGear for jQuery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="../lib/javascripts/tablegear-
jquery.js"></script>
<link type="text/css" rel="stylesheet" href="../lib/stylesheets/
tablegear.css" />
</head>
<body>
<div>
<?= $table->getTable() ?>
</div>
<p>--------------------------- hey let's take a break!
--------------------</p>
<div>
<?= $t2->getTable() ?>
</div>
<?= $table->getJavascript("jquery") ?>
<?= $t2->getJavascript("jquery") ?>
</body>
</html>

Andrew Plummer

unread,
Apr 18, 2011, 11:43:32 PM4/18/11
to TableGear
Hmm... everything is working for me when trying it out... I may have to modify the code you gave me to try to get it to match and find the bug but I really suspect that there's some criss cross or duplication of options hashes and values... Also I notice that you're including "Tablegear1.6.1" as the script but this isn't the newest version... can you maybe try downloading the newest version and using that instead?

Andrew

Monil Chheda

unread,
Apr 19, 2011, 9:01:08 PM4/19/11
to tabl...@googlegroups.com
Andrew, is it possible to share your code (for querying the same
database table) and displaying it on the same page?

Best Regards,
Monil Chheda

Andrew Plummer

unread,
Apr 19, 2011, 9:08:21 PM4/19/11
to tabl...@googlegroups.com
Sure...here ya go.

Andrew
jquery_two_tables.php

Monil Chheda

unread,
Apr 19, 2011, 9:56:25 PM4/19/11
to tabl...@googlegroups.com
Andrew, you were correct. I am able to share multiple calls to
TableGear on the same page with the same table.

I figured that the id needs to be set explicitly for each of them.

Appreciate your help and an excellent product.

Best Regards,
Monil Chheda


On Tue, Apr 19, 2011 at 9:08 PM, Andrew Plummer

Andrew Plummer

unread,
Apr 19, 2011, 10:07:07 PM4/19/11
to tabl...@googlegroups.com

Hm... well that's ok but it should be automatically incrementing the ID! Are you saying that's not happening?

Monil Chheda

unread,
Apr 20, 2011, 8:52:32 AM4/20/11
to tabl...@googlegroups.com
For me, when I am accessing the same table multiple times, it was not
happening. So, when I passed a unique value, it took care of the same.

Best Regards,
Monil Chheda


On Tue, Apr 19, 2011 at 10:07 PM, Andrew Plummer

Andrew Plummer

unread,
Apr 20, 2011, 9:28:04 AM4/20/11
to tabl...@googlegroups.com
Ahhh I see... well I guess that works too!
Reply all
Reply to author
Forward
0 new messages