Ask a Question related to Macromedia Dynamic HTML, Design and Development.
-
Anhialator #1
SQL or PHP?
Hello.
I'm looking at Foundation PHP for Dreamweaver 8, by David Powers, and if
anybody is familiar with the book, maybe they can help answer my question.
Using Dave's random quotations tables authors, quotations in chapter 8: if I
wanted to display every quote by each author, listing the author only once, how
would I do that?
authors table:
Field Type Null
author_id int(10) No
first_name varchar(30) No
family_name varchar(30) No
PRIMARY author_id
quotations table:
Field Type Null
quote_id int(10) No
author_id int(10) Yes
quotation varchar(255) No
PRIMARY quote_id
Currently, to get every quote by each author, the query reads:
SELECT quotations. quotation, authors.first _name, authors.family_name
FROM quotations, authors
WHERE quotations.author_id = author.author_id
But that produces a result listing each authors name for each quote. I want
to list the authors name only once, and then display the list of quotes
associated with each author.
Is that done in the SQL query, or is it done afterward, using PHP?
Thank you so much for your help!!!
Anhialator Guest
-
Murray *ACE* #2
Re: SQL or PHP?
Use a variable for the author's name. Initialize it by setting it to a null
string.
Each pass through your echo loop will test this variable against the actual
name as pulled from the database. If they are different, set the variable
to the actual name and then print the variable.
Does that make sense?
--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
[url]http://www.dreamweavermx-templates.com[/url] - Template Triage!
[url]http://www.projectseven.com/go[/url] - DW FAQs, Tutorials & Resources
[url]http://www.dwfaq.com[/url] - DW FAQs, Tutorials & Resources
[url]http://www.macromedia.com/support/search/[/url] - Macromedia (MM) Technotes
==================
"Anhialator" <webforumsuser@macromedia.com> wrote in message
news:ekspha$t4r$1@forums.macromedia.com...> Hello.
> I'm looking at Foundation PHP for Dreamweaver 8, by David Powers, and if
> anybody is familiar with the book, maybe they can help answer my question.
> Using Dave's random quotations tables authors, quotations in chapter 8:
> if I
> wanted to display every quote by each author, listing the author only
> once, how
> would I do that?
>
> authors table:
> Field Type Null
> author_id int(10) No
> first_name varchar(30) No
> family_name varchar(30) No
> PRIMARY author_id
>
> quotations table:
> Field Type Null
> quote_id int(10) No
> author_id int(10) Yes
> quotation varchar(255) No
> PRIMARY quote_id
>
> Currently, to get every quote by each author, the query reads:
>
> SELECT quotations. quotation, authors.first _name, authors.family_name
> FROM quotations, authors
> WHERE quotations.author_id = author.author_id
>
> But that produces a result listing each authors name for each quote. I
> want
> to list the authors name only once, and then display the list of quotes
> associated with each author.
>
> Is that done in the SQL query, or is it done afterward, using PHP?
>
> Thank you so much for your help!!!
>
>
Murray *ACE* Guest
-
Anhialator #3
Re: SQL or PHP?
Ace,
I'm certain that your reply makes perfect sense, but it's more advanced than I
am. I can follow some of the logic, yes, but not all of it. I'll have to
study some more I guess. Thank you so much for replying!
Anhialator Guest



Reply With Quote

