Showing a subset of data with same table
Showing a subset of data with same table
Description of problem:
One question regarding a structure of MySQL with datatables, because I have a knot in my head right now.
The idea is to show several tables of the same kind, e.g. Journal 1, Journal 2, Journal 3, etc.
The table behind it is always the same. It's just different journals. And the files journal.php, controller.php and journal.js should be always the same. What's the better alternative? Everything in a table and choose accordingly? Or take 3 times everything. So journal1.php, journal2.php, journal1.js, journal2.js, etc.
How can I manage that in the journal.js file if I have only one file?
if ( data.journal == "1")
{
// show only table with data.journal = 1
columns: [
{ data: "journal.id"},
{ data: "journal.trade"},
{ data: "journal.stock"},
{ data: "journal.swap"},
}
// show only table with data.journal = 2
else if (data.journal == "2")
{
columns: [
{ data: "journal.id"},
{ data: "journal.trade"},
{ data: "journal.stock"},
{ data: "journal.swap"},
}
.......
Table: journal1
+----+-------+------+------+
| id | trade | stock| swap |
+----+-------+------+------+
| 1 | 112 | 43 | 1.45 |
| 2 | 223 | 34 | 1.23 |
| 3 | 322 | 23 | 1.24 |
+----+-------+-----+-------+
Table: journal2
+----+-------+------+------+
| id | trade | stock| swap |
+----+-------+------+------+
| 1 | 165 | 43 | 1.45 |
| 2 | 256 | 34 | 1.27 |
| 3 | 672 | 23 | 1.24 |
+----+-------+-----+-------+
Table: journal
+----+-------+------+------+-----
| id | trade | stock| swap | journal
+----+-------+------+------+-----
| 1 | 112 | 43 | 1.45 | 1
| 1 | 165 | 43 | 1.45 | 2
| 2 | 223 | 34 | 1.23 | 1
| 2 | 256 | 34 | 1.27 | 2
| 3 | 322 | 23 | 1.24 | 1
| 3 | 672 | 23 | 1.24 | 2
+----+-------+-----+-------+-----
Thanks for a short hint....
Best regards
Mac
This question has an accepted answers - jump to answer
Answers
Not sure if this is answering your question but you can use
ajax.data
to send the journal ID or whatever to the server. Then your server script can use the parameter value to filter the select results using a where statement. Does this help?Kevin
Hi Kevin,
thanks for the hint. My solution is now this. You can build a link like journal.php?jid=1
header.php:
journal.php:
journal.js:
controller_journal.php
In the controller_journal.php you have the where funtion to filter the table for the right id and set the id to the account. That's it.
Thank you again for the hint.
Best regards
Mac