https://antibiotiqueaugmentin.com/surdosage-augmentin-bebe/

Articles db; display one row for multiple authors

  • dmcole
  • dmcole's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
13 years 3 months ago #1185

I am looking to display a database of back issues of a print magazine and the articles in those back issues on my Joomla 1.5 site. I'm pretty certain that Card View JX will do what I want, except for one thing.

Please see attached image of a screenshot of the first page from phpMyAdmin of the db. You'll note on lines 5 and 6 and 12 and 13, there are two authors for a single article. How do I get the two authors to display under a common line that includes `title` and `page`?

I'm looking for output something like:

*Page 18, Setting up at a train show made them steaming, By Scott E. McDonald.
*Page 20, Series wraps up with a look at sand boxes. By Dan Rowe.
*Page 25, The Aster Alishan Shay. By Ross Schlabach.
*Page 33, Building a steam-powered Model-T rail truck. By Howard Maculsay.
*Page 40, N&W Class J No. 611 electric-to-steam conversion. By Charles Bednarik and Ryan Bednarik.

FWIW, we're running on a hosted environment, Linux running PHP 5.2.17 and MySQL 5.0.91.

Thanks for any insights you might be able to provide.

\dmc

Last edit: 13 years 3 months ago by dmcole.

Please Log in or Create an account to join the conversation.

More
13 years 3 months ago #1186

Hi,

Are you allowed to create views on your environment? If so, than you can create a view from this table ad group by title for example.

CREATE VIEW my_view AS
SELECT * FROM my_table GROUP BY title

Than you use this newly created view and display it with Table JX.

Regards,
Tomaž

Please Log in or Create an account to join the conversation.

  • dmcole
  • dmcole's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
13 years 3 months ago #1187

Tomaz:

Thanks for your response. Yes, I can create views.

I had used that SQL statement (just in the phpMySQL window, not in a view) before and that does not get me both of the author names ... it does eliminate the second iteration of the title, but the second set of author names is not listed.

I tried it again just now and it doesn't work.

Do you have any other thoughts?

\dmc

Please Log in or Create an account to join the conversation.

More
13 years 3 months ago #1188

Hi,

This is quite a hard one..

How about something like this:

SELECT t1.*, t2.author_last AS 2nd_author_last, t2.author_first as 2nd_author_first
FROM my_table as t1
LEFT JOIN my_table as t2 
ON t1.title=t2.title 
AND t1.author_last <> t2.author_last
AND t1.author_first <> t2.author_first

I have not test it, but something like this should work if you do not have more than two authors.

Regards,
Tomaž

Please Log in or Create an account to join the conversation.

  • dmcole
  • dmcole's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
13 years 3 months ago #1189

Tomaž:

Thanks for working on my problem. Your solution works except for some hiccups:

*We have instances where a father and son are co-authors, and so the fields author_last are equal, which means the code doesn't work at all. If the co-authors have different last names, it works, inserting the second author's name into the new fields 2nd_author_last and 2nd_author_first.

*Sometimes the titles are the same across multiple issues (hadn't noticed this myself until just how); so the equivalence needs to be both title and issue.

*The second author's record is still displayed (should be suppressed somehow).

I guess some pseudo code might read like

If title and issue are equal and both author_first and author_last aren't equal, then put a second author's name into 2nd_author_first and 2nd_author_last and eliminate this record from displaying at all.

I have queried a number of different SQL experts on this problem and you've come the closest of any of them, so you're on the right track.

I appreciate your help.

\dmc

Please Log in or Create an account to join the conversation.

More
13 years 3 months ago #1190

Hi

I think that the following should do what you want:

SELECT t1.*, t2.author_last AS 2nd_author_last, t2.author_first as 2nd_author_first
FROM my_table as t1
LEFT JOIN my_table as t2 
ON (t1.title=t2.title AND t1.issue = t2.issue)
AND (t1.author_last <> t2.author_last
OR t1.author_first <> t2.author_first)
GROUP BY t1.title, t1.issue

Best regards,
Tomaž

Please Log in or Create an account to join the conversation.

Moderators: tomaz
Time to create page: 0.140 seconds

Contact Us

Contact us on Discord

Contact us on Facebook