SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    While Loop Doesn't Display 2nd Row

    Below is the query I'm working with...

    PHP Code:
    $res mysql_query ("SELECT SMP.N, SMP.URL, SMP.Name_First, SMP.Name_Middle, SMP.Name_Last,
    SMGov.URL, SMGov.Term_Began, SMGov.Term_Ended, SMGov.Party G_P, SMGov.Notes, SMGov.Image,
    SMM.URL, SMM.Term_Began TermB, SMM.Term_Ended TermE, SMM.Party M_P, SMM.Notes M_N,
    SMW.URL, SMW.Class,
    SMWA.URL, SMWA.Org, SMWA.Title, SMWA.Year_Began, SMWA.Year_Ended, SMWA.Year_Mid
    FROM sm_ppl SMP
    LEFT JOIN sm_ppl_gov SMGov ON SMGov.URL = SMP.URL
    LEFT JOIN sm_ppl_mayor SMM ON SMM.URL = SMP.URL
    LEFT JOIN sm_ppl_wrrs SMW ON SMW.URL = SMP.URL
    LEFT JOIN sm_ppl_wrrs_assoc SMWA ON SMWA.URL = SMP.URL
    WHERE SMP.URL = '
    $MyURL'") or die (mysql_error());

    while (
    $row mysql_fetch_array ($res))
    {
    $TermB $row['TermB'];
    $TermE $row['TermE'];

    echo 
    $TermB;

    echo 
    $TermE;

    The query includes the following aliases...

    Code:
    SMM.Term_Began TermB, SMM.Term_Ended TermE
    ...which are echoed at the bottom of the script.

    It works for one-term mayors, but it doesn't display the second row for people who had split terms, as follows:

    Code:
    URL | Term_Began | Term_Ended
    Hiram_Gill | 1910 | 1911
    Jay_Scott | 1911 | 1914
    Hiram_Gill | 1914 | 1916
    For Hiram Gill, it displays just 1910 and 1911 (not 1914 and 1916), even though I inserted the echo statement inside the while loop. Any tips?

    Thanks.

  2. #2
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you run your query directly in MySQL (e.g. via phpMyAdmin) and verify that the query is returning what you expect? My instinct is that if the while loop is not echoing all your data, you're not getting all your data from your query.
    PHP questions? RTFM
    MySQL questions? RTFM

  3. #3
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kromey View Post
    Have you run your query directly in MySQL (e.g. via phpMyAdmin) and verify that the query is returning what you expect? My instinct is that if the while loop is not echoing all your data, you're not getting all your data from your query.
    Interesting; I'd never done that with joined tables before. Anyway, it displays the data perfectly - two separate rows for table sm_ppl_mayor, the same row twice for the master table, sm_ppl, and a series of NULL's for cells in tables that have no information on this individual.

    I also tried...

    PHP Code:
    echo $row['TermB']; 
    ...with the same results.

  4. #4
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please ignore this thread; I finally found the bug. Thanks.
    Last edited by geosite; Jun 19, 2007 at 17:42.


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
  •