SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Lookup Display

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2002
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lookup Display

    Hi all

    I have been using Yank's 'Build Your Own...' book - what a great resource.

    In Chapter 6, Kevin's examples of retrieving / displaying data from a lookup table (category lookup for the jokes) seem to only focus on displaying one actual record, rather than a complete list, with the categories shown.

    I follow the syntax used for showing the categories used for one record, but what if I want a complete list, showing the categories as well?

    Can you use a while loop inside another while loop? (I experimented with this for a while - but went round in circles - no pun intended)

    Or is there a special sort of table join you can use, that gives one row per record, and creates columns for values in another table? (I'm not sure how else to express what I'm saying here - I think it's like a pivotable in MS Access)

    Or is there a way of using SELECT DISTINCT which shows only distinct (Jokes).

    Ian

  2. #2
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I don't know the exact code you refer to, but it sounds like he'll have some sort of SELECT WHERE part in there, remove the WHERE which limits it to one field and you should retrieve all...
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2002
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Further.....

    Thanks for the reply - I should be a bit more specific then - I'll use my own examples, rather than the one from Yank's book.

    3 tables - calendar, contact, and calendar_lookup. The idea is that each calendar entry can have a contact/s assigned to it via the calendar_lookup table.

    The question is, what syntax (either php, or sql) can I use so that I can display each calendar entry only once, yet also display which contact each calendar entry has assigned to it?

    The standard left join creates a new row for every calendar entry, plus every contact entry (thus lots of rows, rather than one row per calendar entry).

    This is why I asked the question about 'while loops within while loops' - not sure if that is possible or not. Or is there a special sort of query / join whereby new columns are generated based on the data in (eg) the contacts table.

    Hope this clarifies.....

    Ian
    Last edited by ianmarie; Dec 14, 2002 at 17:07.

  4. #4
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah-ha, now I'm with ya I could be wrong, but it sounds like you're wanting to do a subselect, which isn't available in mySQL 3.x (which I assume you're using).

    But yes you can do whiles within whiles. In the style of Kevs book:

    PHP Code:
    // you'll need to grab calendar days
    $result=mysql_query("SELECT * from calendar");

    while (
    $something=mysql_fetch_array($result)) {

    $newselect=mysql_query("SELECT * from contact WHERE [match lookuptablehere]");

    while { }


    There might be a better way but it's too late for me to figure it out
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2002
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks - I'll try it

    The code looks good so I'll try it. However I'm wondering about the final while {} - what does this mean - with the empty brackets?

    Thanks

    Ian

  6. #6
    As the name suggests... trickie's Avatar
    Join Date
    Jul 2002
    Location
    Melbourne, Australia
    Posts
    678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats were you put the code for the nested while statement.

  7. #7
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Thanks - I'll try it

    Originally posted by ianmarie
    The code looks good so I'll try it. However I'm wondering about the final while {} - what does this mean - with the empty brackets?

    Thanks

    Ian
    Yeh that wasn't the actual code, more like pseudo code. You'll need to fill in the gaps to make it fit your requirements.
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky


Bookmarks

Posting Permissions

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