2 Database Tables (not 2 datatables)

2 Database Tables (not 2 datatables)

SanjaySanjay Posts: 6Questions: 0Answers: 0
edited June 2012 in DataTables 1.9
Having spent the last 3 or so hours on this site and implementing many versions of this fantastic application, on a XAMPP and also live hosting, purely for learning and experience, I have a problem I hope I could be helped with.

I have successfully managed to connect a database connection and single database table and all works well, but I wanted to expand this to have this application work with 2 database tables.

Essentially Database_Table_TWO has a foreign key which is the primary key of Database_Table_ONE, so while viewing all rows from Database_Table_TWO, additional data can be presented which is held in Database_Table_ONE (thus avoiding unnecessary duplication of data).

I realise I have no code to show here, but viewing "server_processing.php" I see
[code] ...
/* DB table to use */
$sTable = "Database_Table_NAME";
... [/code]

so, would I begin by declaring the second Database_Table_NAME above. Any pointers would be much appreciated. Thanks...


I have read many of the 2 table posts but feel they are in fact 2 DataTables issues and not 2 database tables related.

Replies

  • koosvdkolkkoosvdkolk Posts: 169Questions: 0Answers: 0
    Why don't you use a SQL JOIN to get the data from both tables in one result set?
  • SanjaySanjay Posts: 6Questions: 0Answers: 0
    It would be nice if a simple 2 database table example was among the many other examples given here.

    All wonderful stuff, but having spent many hours again tonight trying to implement the JOIN suggestion (on 2 database tables), and having read many (but what seems like all at this point) of the relevant forum posts, I am a little surprised no working "2 database tables" example has been provided.

    Of course it is my lack of knowledge here that is the issue and not the developer or the site (which both seem wonderful), but could I implore the developer (Allan) to provide a suitable simple example at some point in the future.

    p.s. I have read somewhere and agree it is not at all possible to supply examples for every single implementation, but a simple 2 database table example with 3 fields each and perhaps a handful of records, connected with primary and foreign keys, would be so super helpful (to so many of us).
  • koosvdkolkkoosvdkolk Posts: 169Questions: 0Answers: 0
    I think the thing you want is beyond the intention of Datatables. Datatables is just a (nice) way of showing data in a browser. Your request is about obtaining data from a database. I dont think Allan wants to help with this, because the next person will ask another SQL thing, the next person another, etc.

    [quote]could I implore the developer (Allan) to provide a suitable simple example at some point in the future.[/quote]

    If you really want Allan to come up with a tailored solution, please consider buying support: http://datatables.net/support. In the end, Allan has to pay his bills as well :)
  • SanjaySanjay Posts: 6Questions: 0Answers: 0
    [quote] If you really want Allan to come up with a tailored solution...[/quote]

    No it's not a tailored solution I was looking for at all. But having read a great deal of similar difficulties as mine, I just thought a simple example as stated above would be hugely useful (again, not just for me, but for many of the unresolved threads I have read on this particular matter).

    Thanks for your input...
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    As koosvdkolk says, this isn't really the place to ask SQL questions - although it is obviously a related subject, this is primarily a Javascript forum (since DataTables is a Javascript library). The way you want to get your data from the database for DataTables is exactly the same way as if you weren't using DataTables - i.e. get your SQL statement working (experiment with it in phpMyAdmin or whatever).

    Allan
  • SanjaySanjay Posts: 6Questions: 0Answers: 0
    So I got my 2 Database Tables working (where a set of TABLE_LIST_ITEMS are categorised by a foreign key which is the primary key in the TABLE_LIST_CATEGORIES --- so as each item is listed, a category is shown from another table).

    A huge help was found in another post, which I will link to here in case anyone else comes across this thread and had the same initial difficulty understanding usage.

    LINK: http://datatables.net/forums/discussion/4215/pulling-data-from-multiple-mysql-tables...-need-help-please/p1

    or Search:
    "Pulling data from multiple mySQL tables... NEED HELP please!"
This discussion has been closed.