Ask a Question related to Macromedia Dynamic HTML, Design and Development.

  1. #1

    Default 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

  2. #2

    Default 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

  3. #3

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139