michal
Založený: 17.06.2003
Príspevky: 537
Bydlisko: Slovakia
Zaslal: 2004-05-20 15:33
Návrat hore
Odpovedať s citátom
|
i have a classic author-books db:
author.id
author.name
book.id
book.author_id
book.name
where author.id = book.author_id
i want to display authors that have at least one book, with two fields: author's name and number of his books.
1. sql command would look like:
| Kód: |
SELECT author.name as name, COUNT(*)
FROM author, LEFT OUTER JOIN book ON author.id = book.author_id
WHERE 1
GROUP BY author.id
HAVING COUNT(*) > 0
|
(?)
2. this cannot be implement in current pme (?) because $opts['filters'] is used with (..) around it.
3. if a new option is appended after 'filters' (without (..)) containing HAVING and ORDER stuff, it would work. (?)
|
hbernard
Založený: 23.03.2003
Príspevky: 159
Bydlisko: FRANCE
Zaslal: 2004-05-20 16:50
Návrat hore
Odpovedať s citátom
|
| michal Napísal: |
1. sql command would look like:
| Kód: |
SELECT author.name as name, COUNT(*)
FROM author, LEFT OUTER JOIN book ON author.id = book.author_id
WHERE 1
GROUP BY author.id
HAVING COUNT(*) > 0
|
(?)
|
Simply use custom join clause to have :
SELECT author.name as name
FROM author, LEFT OUTER JOIN book
ON author.id = book.author_id AND book.author_id is not null
WHERE 1
| Citácia: |
| 2. this cannot be implement in current pme (?) because $opts['filters'] is used with (..) around it. |
I don't understand this.
Having parenthesis is no problem, I think ?
| Citácia: |
| 3. if a new option is appended after 'filters' (without (..)) containing HAVING and ORDER stuff, it would work. (?) |
Lot of work, because you need to specify a GROUP BY clause, and so on.
IMHO, PME should simply allow to have custom full SQL query.
_________________ hbernard - phpMyEdit updater.
|
hbernard
Založený: 23.03.2003
Príspevky: 159
Bydlisko: FRANCE
Zaslal: 2004-05-20 16:55
Návrat hore
Odpovedať s citátom
|
| hbernard Napísal: |
Simply use custom join clause to have :
SELECT author.name as name
FROM author, LEFT OUTER JOIN book
ON author.id = book.author_id AND book.author_id is not null
WHERE 1
|
Sorry, not exactly.
1. you will not have the number of books
2. you will get duplicate lines. (one per book)
So this not directly doable with current PME.
What I m currently doing in such case is to generate temporary table on the fly before calling PME on it.
Then I join initial temporary table to new changed (if edited) temporary table, and do updates in the real database model
_________________ hbernard - phpMyEdit updater.
|
hbernard
Založený: 23.03.2003
Príspevky: 159
Bydlisko: FRANCE
Zaslal: 2004-05-23 21:40
Návrat hore
Odpovedať s citátom
|
| doug Napísal: |
| hbernard Napísal: |
... to generate a temporary table on the fly before calling PME on it. Then I join initial temporary table to new changed (if edited) temporary table, and do updates in the real database model |
I understand how to select data into temporary tables, but never considered trying to access temporary table using phpMyEdit. If you have the time to post an example sometime, I would appreciate it. |
Well, my samples are hard to simplify for demo purpose, however, the steps are :
(in the calling script)
at the top, call these querys :
DROP TABLE my_temp if exists;
create temporary table my_temp SELECT ....
[usual calling script, working on the my_temp tb.
at the bottom of th calling script :
perform SQL updates of real tables using new syntax allowing multiples updated tables
Will build an example from scratch if I have some time.
This allow to make whatever you want, because you may adapt the temporary datas to phpMySql constraint.
the DROP / CREATE is run each load of the page, however, my mysql server cache lot of these querys, so it's still efficient on not too big database.
_________________ hbernard - phpMyEdit updater.
|
hsicard
Založený: 22.10.2003
Príspevky: 17
Zaslal: 2004-07-08 15:22
Návrat hore
Odpovedať s citátom
|
Your methods look very powerfull. I hope you'll soon have some time to tell us more...
Merci!
|
hsicard
Založený: 22.10.2003
Príspevky: 17
Zaslal: 2004-10-23 11:53
Návrat hore
Odpovedať s citátom
|
I implemented the method you mentioned, creating and deleting a temporary table on the fly. I use it to insert a file upload field within the view page.
It works great except after inserting records: while populating the temporary table before displaying the View page, my query don't find the new field inserted (a reload of the page is necessary).
Would you have an idea on how to make sure that after insert queries take into account inserted records?
PS: hbernard, nous portons le meme prénom. Or je suis bcp moins actif que toi sur ce projet. J'ai cherché a changer mon login en hsicard mais il semble que ce ne soit pas possible... Me trompe-je?
|
hbernard
Založený: 23.03.2003
Príspevky: 159
Bydlisko: FRANCE
Zaslal: 2004-11-01 13:11
Návrat hore
Odpovedať s citátom
|
| Hugues Napísal: |
It works great except after inserting records: while populating the temporary table before displaying the View page, my query don't find the new field inserted (a reload of the page is necessary).
Would you have an idea on how to make sure that after insert queries take into account inserted records?
|
mmh, this is certainly because the calling script is processed first and then the class do the insert.
You should try to update the temporary table during the 'select'
pre
-triggers (?)
| Hugues Napísal: |
PS: hbernard, nous portons le meme prénom. Or je suis bcp moins actif que toi sur ce projet. J'ai cherché a changer mon login en hsicard mais il semble que ce ne soit pas possible... Me trompe-je? |
je pense que la seule option est de déclarer un nouveau login :-(
--Hugues (aka hbernard)
_________________ hbernard - phpMyEdit updater.
|
michal
Založený: 17.06.2003
Príspevky: 537
Bydlisko: Slovakia
Zaslal: 2004-11-07 22:58
Návrat hore
Odpovedať s citátom
|
| hsicard Napísal: |
| hbernard Napísal: |
je pense que la seule option est de déclarer un nouveau login :-(
|
Soit!
--Hugues (aqui hsicard) |
ton login est possible a changer, couriele a nepto. (c'est possible a changer le db)
(i wanted to write that it's possible to change your login, email to nepto (he can change the database of forum))
michal (aka michal ;-) )
|
hsicard
Založený: 22.10.2003
Príspevky: 17
Zaslal: 2005-06-06 17:30
Návrat hore
Odpovedať s citátom
|
Finally did someone came up with a better
solution than creating a temporary table?
|
|
Odoslať novú tému
Odpovedať na tému
|