SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Jan 2012
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need a static (non-repeating) row in a while loop

    I'm displaying a somewhat complex table inside a WHILE LOOP with the following code...

    Code:
    switch ($DesigGroup)
    {
    case 'Animals':
    case 'Plants':
    
    // This displays plants and animals...
    echo <<<EOD
       <tr class="$DesigGroup $Alternate" style="background-color:$c">
         <td class="$class"><a href="/World/$URL">$Check$DesigD</a>$ast</td>
         <td class="left">$Symbol</td>
         <td class="latin">$Latin</td>
         <td class="left">$Year</td>
       </tr>
    EOD;
    break;
    
    // EARTH...
    case 'earth':
    // INTERNAL SWITCH
    switch ($DesigGen)
    {
     case 'fossil':
    // This displays fossils...
    echo <<<EOD
       <tr class="{$row["DesigGroup"]} $Alternate" style="background-color:$c">
         <td class="$class"><a href="/World/$URL">$Check$DesigD</a>$ast</td>
         <td class="left">$Symbol</td>
         <td class="latin">$Latin</td>
         <td class="left">$Year</td>
       </tr>
    EOD;
    break;
    Now I want to insert a couple non-repeating rows that aren't associated with the database table in any way. If I simply insert them, as in the example below, they display but they repeat. Is there some way I can tell a row inside a while loop to display just once?

    Other than that, the first row begins in the right location, so that should fix it. The second row is more complicated, but I can probably make it display in the right location if I can just get it to display just once.

    Thanks!

    Code:
    switch ($DesigGroup)
    {
    case 'Animals':
    case 'Plants':
    
    // NON-REPEATING ROW #1
    echo '<tr><td colspan="4" style="background: #060; color: #fff; text-align: center;"><strong>EcoSymbols</strong></td></tr>';
    // This displays plants and animals...
    echo <<<EOD
       <tr class="$DesigGroup $Alternate" style="background-color:$c">
         <td class="$class"><a href="/World/$URL">$Check$DesigD</a>$ast</td>
         <td class="left">$Symbol</td>
         <td class="latin">$Latin</td>
         <td class="left">$Year</td>
       </tr>
    EOD;
    // NON-REPEATING ROW #2
    echo '<tr><td colspan="4" style="background: #009; color: #fff; text-align: center;"><strong>Cultural Symbols</strong></td></tr>';
    break;
    
    // EARTH...
    case 'earth':
    // INTERNAL SWITCH
    switch ($DesigGen)
    {
     case 'fossil':
    // This displays fossils...
    echo <<<EOD
       <tr class="{$row["DesigGroup"]} $Alternate" style="background-color:$c">
         <td class="$class"><a href="/World/$URL">$Check$DesigD</a>$ast</td>
         <td class="left">$Symbol</td>
         <td class="latin">$Latin</td>
         <td class="left">$Year</td>
       </tr>
    EOD;
    break;

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,509
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Can you show us the final result you want to have?

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    How about you post an array with say 2 or 3 sets, and then show how the resulting table should look. Leave out all the html class and style gubbins, just stick to the data and the basic table you want -- and lets focus on the basic logic and the loop.

    Create your simplified array and then post the output of:
    PHP Code:
    echo var_export($array1); 

  4. #4
    SitePoint Addict
    Join Date
    Jan 2012
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Can you show us the final result you want to have?
    Sure. I hope it's OK to post the code for the entire table. I deleted most of the styling to make it easier to read.

    There is at least one other thing I need to fix. It should display a row for each of a state's nicknames (three, in this case). However, I need to play around with my database and query first. If I can't figure out how to make it work, maybe I'll have to learn a new trick.

    Thanks.

    Code:
    <thead>
      <tr>
        <th>Designation</th>
        <th>Symbol</th>
        <th><em>Scientific Name</em></th>
        <th>Year</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td colspan="4" style="background: #009; color: #ff0; text-align: center;"><strong>Symbols of State</strong></td>
      </tr>
      
    // EVERYTHING BELOW HERE IS INSIDE A WHILE LOOP
      
      <tr>
        <td><a href="/World/Arizona/Flag">Flag</a></td>
        <td></td>
        <td>1917</td>
      </tr>
      <tr>
        <td><a href="/World/Arizona/Seal">Seal</a></td>
        <td></td>
        <td>1911</td>
      </tr>
      <tr>
        <td><a href="/World/Arizona/Nickname">Nickname</a></td>
        <td>The Grand Canyon State</td>
        <td></td>
      </tr>
      <tr>
        <td><a href="/World/Arizona/Motto">Motto</a></td>
        <td>Ditat Deus&nbsp;&nbsp;<span style="font-size: 85%; background: #009;">[<a href="/World/Arizona/Motto">(Latin...)</a>]</span></td>
        <td>1864</td>
      </tr>
      <tr>
        <td><a href="/World/Arizona/Song">Anthem</a></td>
        <td>Arizona March Song</td>
        <td>1919</td>
      </tr>
      <tr>
        <td><a href="/World/Arizona/Song2">Alternate Anthem</a></td>
        <td>Arizona</td>
        <td>1981</td>
      </tr>
    
    * * * * *
    // I WANT TO INSERT THE FOLLOWING STATIC ROW
    <tr><td colspan="4" style="background: #060; color: #fff; text-align: center;"><strong>EcoSymbols</strong></td></tr>
    * * * * *
    
      <tr>
        <td><a href="/World/Arizona/Flower"><img src="http://Geobop/images/Site/aids/check15.gif" width="15" height="15" alt="check mark (article available)" style="margin-left: -9px; margin-right: 2px;">Flower</a></td>
        <td>saguaro cactus blossom</td>
        <td class="latin">Carnegia gigantea</td>
        <td>1931</td>
      </tr>
      <tr>
        <td><a href="/World/Arizona/Tree"><img src="http://Geobop/images/Site/aids/check15.gif" width="15" height="15" alt="check mark (article available)" style="margin-left: -9px; margin-right: 2px;">Tree</a></td>
        <td>palo verde</td>
        <td class="latin">Cercidium</td>
        <td>1954</td>
      </tr>
      <tr>
        <td><a href="/World/Arizona/Bird"><img src="http://Geobop/images/Site/aids/check15.gif" width="15" height="15" alt="check mark (article available)" style="margin-left: -9px; margin-right: 2px;">Bird</a></td>
        <td>cactus wren</td>
        <td class="latin">Campylorhynchus brunneicapillus</td>
        <td>1931</td>
      </tr>
      <tr>
        <td><a href="/World/Arizona/Mammal">Mammal</a></td>
        <td>ringtail</td>
        <td class="latin">Bassariscus astutus</td>
        <td>1986</td>
      </tr>
      <tr>
        <td><a href="/World/Arizona/Reptile">Reptile</a></td>
        <td>ridge-nosed rattlesnake</td>
        <td class="latin">Coluber constrictor</td>
        <td>1986</td>
      </tr>
      <tr>
        <td><a href="/World/Arizona/Amphibian">Amphibian</a></td>
        <td>Arizona tree frog</td>
        <td class="latin">Hyla eximia</td>
        <td>1986</td>
      </tr>
      <tr>
        <td><a href="/World/Arizona/Fish">Fish</a></td>
        <td>Arizona trout</td>
        <td class="latin">Oncorhynchus apache</td>
        <td>1986</td>
      </tr>
      <tr>
        <td><a href="/World/Arizona/Insect">Butterfly</a></td>
        <td>two-tailed swallowtail</td>
        <td class="latin">Papilio multicaudata</td>
        <td>2001</td>
      </tr>
      <tr>
        <td><a href="/World/Arizona/Soil">Soil</a></td>
        <td>Casa Grande</td>
        <td></td>
      </tr>
      <tr>
        <td><a href="/World/Arizona/Fossil">Fossil</a></td>
        <td>Arizona petrified wood</td>
        <td>1988</td>
      </tr>
      <tr>
        <td><a href="/World/Arizona/Mineral">Mineral</a></td>
        <td>fire agate</td>
        <td></td>
      </tr>
      <tr>
        <td><a href="/World/Arizona/Gem">Gem</a></td>
        <td>turquoise</td>
        <td>1974</td>
      </tr>
    
    * * * * *
    // I WANT TO INSERT THE FOLLOWING STATIC ROW
    <tr><td colspan="4" style="background: #009; color: #fff; text-align: center;"><strong>Cultural Symbols</strong></td></tr>
    * * * * *
    
      <tr>
        <td><a href="/World/Arizona/Colors">Colors</a></td>
        <td>blue and gold</td>
        <td>1931</td>
      </tr>
      <tr>
        <td><a href="/World/Arizona/Neckwear">Neckwear</a></td>
        <td>bola tie</td>
        <td>1973</td>
      </tr>
    </tbody>
    </table>

  5. #5
    SitePoint Addict
    Join Date
    Jan 2012
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yikes, I'm afraid I'm lost with arrays; I just began working with them a few weeks ago and don't really understand what you're saying.

    Maybe it will help if I give a basic overview, though. First, I have a database table that lists symbols of various nations and states. It probably needs to be modified, but it's working pretty good so far.

    One key row is URL, which simply lists each page's URL, like Arizona/Flag or Arizona/Flower

    Another key row is Symbol, which lists the name of each symbol, like "saguaro cactus blossom" for Arizona's state flower. However, it doesn't list names for flags or coats of arms, since they don't have names.

    Three other key rows...

    DesigGroup - Values include Flags, Animals, Plants, Minerals, etc. This helps me organize everything into categories.

    DesigGeneral - This helps me refine my classification, with values like Flowers, Trees, Fruit, etc.

    Desig - If a flower is recognized as the "national flower," then this value is null. However, if there's a unique designation, like "Official Environmental Symbol," then that's the value.

    The dynamic rows are displayed with several blocks of code...

    Code:
    // This displays plants, animals and minerals. Since the table is ordered by the numerical key, they actually appear in the middle of the table.
    echo <<<EOD
       <tr class="$DesigGroup $Alternate" style="background-color:$c">
         <td class="$class"><a href="/World/$URL">$Check$DesigD</a>$ast</td>
         <td class="left">$Symbol</td>
         <td class="latin">$Latin</td>
         <td class="left">$Year</td>
       </tr>
    EOD;
    
    // The next two block display earth symbols, which are listed just after plants and animals...
    switch ($DesigGen)
    {
     case 'fossil':
    // This displays fossils...
    echo <<<EOD
       <tr class="{$row["DesigGroup"]} $Alternate" style="background-color:$c">
         <td class="$class"><a href="/World/$URL">$Check$DesigD</a>$ast</td>
         <td class="left">$Symbol</td>
         <td class="latin">$Latin</td>
         <td class="left">$Year</td>
       </tr>
    EOD;
    
    // This displays other earth symbols...
    echo <<<EOD
       <tr class="{$row["DesigGroup"]} $Alternate" style="background-color:$c">
         <td class="$class"><a href="/World/$URL">$Check$DesigD</a>$ast</td>
         <td colspan="2" class="left">$Symbol</td>
         <td class="left">$Year</td>
       </tr>
    
    // This displays mottoes...
    switch ($DesigGen)
    {
     case 'motto':
      // INTERNAL SWITCH
      switch ($row['Language'])
      {
       case '':
       $StyleS = '';
       $Language = '';
       break;
       default:
       $StyleS = ' style="font-style: oblique;"';
       $Language = '&nbsp;&nbsp;<span style="font-size: 85%; background: #009;">[<a href="/World/'.$MyName.'/Motto">('.$row['Language'].'...)</a>]</span>';
       break;
      }
      // END INTERNAL SWITCH
     break;
     default:
     $Language = '';
     break;
    }
    
    // And this displays all the other symbols, including "Top Symbols" (which appear at the top of the table) and "Cultural Symbols" (which appear at the end)....
    echo <<<EOD
       <tr class="{$row["DesigGroup"]} $Alternate" style="background:$c">
         <td class="$class"><a href="/World/$URL">$Check$DesigD</a>$ast</td>
         <td colspan="2" class="left">$Symbol$Language</td>
         <td class="left">$Year</td>
       </tr>
    EOD;
    But like I said, I'll probably modify my database table a bit before I get it all figured out.

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    From what you are saying, you are getting some data from mysql.

    This will most likely be an array of results which you have to loop through judging by this comment in your OP:

    I'm displaying a somewhat complex table inside a WHILE LOOP with the following code...
    If you use var_export to output that array of results, and trim it down a bit if necessary so that it isnt reams of code but does typify your problem, then maybe someone can help you output that array into a simplified version of your table -- to which you can then add the bells and whistles.

    I mean, I think I understand your problem and I could generate an array of test values to show how to add these static rows as you call them, but you'd then face problems matching that to your own use case. Dealing with a typical subset of values which you are already grabbing from your db will be much easier for you to understand.

    If you have problems understanding my var_export code,
    PHP Code:
    echo var_export($yourMysqlResults1); 
    then just do this:
    PHP Code:
    var_dump($yourMysqlResults); 
    ... but the output of var_dump just means that in order to recreate your problem, or test any solutions some of us would have to type out the array again.

    Some of us a much cleverer and can do all this stuff accurately in our heads, I am not one.

  7. #7
    SitePoint Addict
    Join Date
    Jan 2012
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, now I understand what you mean. OK, I posted your code inside the while loop and replaced $yourMysqlResults with $row. I got the following results for var_export:

    Code:
    array ( 0 => '3160', 'N' => '3160', 1 => 'us-az', 'GID' => 'us-az', 2 => 'Arizona/Flag', 'URL' => 'Arizona/Flag', 3 => 'Flag', 'PostURL' => 'Flag', 4 => 'Arizona’s State Flag', 'Title' => 'Arizona’s State Flag', 5 => '3', 'MyKind2' => '3', 6 => 'flag', 'DesigGen' => 'flag', 7 => 'Vex', 'DesigGroup' => 'Vex', 8 => '', 'Symbol' => '', 9 => '', 'Desig' => '', 10 => '', 11 => '1917', 'Date' => '1917', 12 => '', 'Common' => '', 13 => 'Olea_europaea', 'Latin' => 'Olea_europaea', 14 => NULL, 'MottoURL' => NULL, 15 => NULL, 'Language' => NULL, 16 => NULL, 'Motto' => NULL, 17 => 'us-az', 'ID' => 'us-az', 18 => 'Flag', 19 => '', 'Article' => '', ) array ( 0 => '3161', 'N' => '3161', 1 => 'us-az', 'GID' => 'us-az', 2 => 'Arizona/Seal', 'URL' => 'Arizona/Seal', 3 => 'Seal', 'PostURL' => 'Seal', 4 => 'Arizona’s State Seal', 'Title' => 'Arizona’s State Seal', 5 => '3', 'MyKind2' => '3', 6 => 'seal', 'DesigGen' => 'seal', 7 => 'Vex', 'DesigGroup' => 'Vex', 8 => '', 'Symbol' => '', 9 => '', 'Desig' => '', 10 => '', 11 => '1911', 'Date' => '1911', 12 => '', 'Common' => '', 13 => 'Olea_europaea', 'Latin' => 'Olea_europaea', 14 => NULL, 'MottoURL' => NULL, 15 => NULL, 'Language' => NULL, 16 => NULL, 'Motto' => NULL, 17 => 'us-az', 'ID' => 'us-az', 18 => 'Seal', 19 => '', 'Article' => '', ) array ( 0 => '3162', 'N' => '3162', 1 => 'us-az', 'GID' => 'us-az', 2 => 'Arizona/Nickname', 'URL' => 'Arizona/Nickname', 3 => 'Nickname', 'PostURL' => 'Nickname', 4 => 'Arizona’s Nicknames', 'Title' => 'Arizona’s Nicknames', 5 => '3', 'MyKind2' => '3', 6 => 'nickname', 'DesigGen' => 'nickname', 7 => 'Top', 'DesigGroup' => 'Top', 8 => 'The Grand Canyon State', 'Symbol' => 'The Grand Canyon State', 9 => '', 'Desig' => '', 10 => 'The Grand Canyon State', 11 => '', 'Date' => '', 12 => NULL, 'Common' => NULL, 13 => NULL, 'Latin' => NULL, 14 => NULL, 'MottoURL' => NULL, 15 => NULL, 'Language' => NULL, 16 => NULL, 'Motto' => NULL, 17 => 'us-az', 'ID' => 'us-az', 18 => 'Nickname', 19 => '', 'Article' => '', ) array ( 0 => '3163', 'N' => '3163', 1 => 'us-az', 'GID' => 'us-az', 2 => 'Arizona/Motto', 'URL' => 'Arizona/Motto', 3 => 'Motto', 'PostURL' => 'Motto', 4 => 'Arizona’s State Motto', 'Title' => 'Arizona’s State Motto', 5 => '3', 'MyKind2' => '3', 6 => 'motto', 'DesigGen' => 'motto', 7 => 'Top', 'DesigGroup' => 'Top', 8 => 'Ditat Deus', 'Symbol' => 'Ditat Deus', 9 => '', 'Desig' => '', 10 => 'Ditat Deus', 11 => '1864', 'Date' => '1864', 12 => NULL, 'Common' => NULL, 13 => NULL, 'Latin' => NULL, 14 => 'Arizona/Motto', 'MottoURL' => 'Arizona/Motto', 15 => 'Latin', 'Language' => 'Latin', 16 => 'Ditat_Deus', 'Motto' => 'Ditat_Deus', 17 => 'us-az', 'ID' => 'us-az', 18 => 'Motto', 19 => '', 'Article' => '', ) array ( 0 => '3164', 'N' => '3164', 1 => 'us-az', 'GID' => 'us-az', 2 => 'Arizona/Song', 'URL' => 'Arizona/Song', 3 => 'Song', 'PostURL' => 'Song', 4 => 'Arizona’s State Anthem', 'Title' => 'Arizona’s State Anthem', 5 => '3', 'MyKind2' => '3', 6 => 'song', 'DesigGen' => 'song', 7 => 'Top', 'DesigGroup' => 'Top', 8 => 'Arizona March Song', 'Symbol' => 'Arizona March Song', 9 => 'Anthem', 'Desig' => 'Anthem', 10 => 'Arizona March Song', 11 => '1919', 'Date' => '1919', 12 => NULL, 'Common' => NULL, 13 => NULL, 'Latin' => NULL, 14 => NULL, 'MottoURL' => NULL, 15 => NULL, 'Language' => NULL, 16 => NULL, 'Motto' => NULL, 17 => 'us-az', 'ID' => 'us-az', 18 => 'Song', 19 => '', 'Article' => '', ) array ( 0 => '3165', 'N' => '3165', 1 => 'us-az', 'GID' => 'us-az', 2 => 'Arizona/Song2', 'URL' => 'Arizona/Song2', 3 => 'Song2', 'PostURL' => 'Song2', 4 => 'Arizona’s Alternate State Anthem', 'Title' => 'Arizona’s Alternate State Anthem', 5 => '3', 'MyKind2' => '3', 6 => 'song', 'DesigGen' => 'song', 7 => 'Top', 'DesigGroup' => 'Top', 8 => 'Arizona', 'Symbol' => 'Arizona', 9 => 'Alternate Anthem', 'Desig' => 'Alternate Anthem', 10 => 'Arizona', 11 => '1981', 'Date' => '1981', 12 => NULL, 'Common' => NULL, 13 => NULL, 'Latin' => NULL, 14 => NULL, 'MottoURL' => NULL, 15 => NULL, 'Language' => NULL, 16 => NULL, 'Motto' => NULL, 17 => 'us-az', 'ID' => 'us-az', 18 => 'Song2', 19 => '', 'Article' => '', ) array ( 0 => '3166', 'N' => '3166', 1 => 'us-az', 'GID' => 'us-az', 2 => 'Arizona/Flower', 'URL' => 'Arizona/Flower', 3 => 'Flower', 'PostURL' => 'Flower', 4 => 'Arizona’s State Flower', 'Title' => 'Arizona’s State Flower', 5 => '3', 'MyKind2' => '3', 6 => 'flower', 'DesigGen' => 'flower', 7 => 'Plants', 'DesigGroup' => 'Plants', 8 => 'saguaro cactus blossom', 'Symbol' => 'saguaro cactus blossom', 9 => '', 'Desig' => '', 10 => 'saguaro cactus blossom', 11 => '1931', 'Date' => '1931', 12 => 'saguaro cactus blossom', 'Common' => 'saguaro cactus blossom', 13 => 'Carnegia_gigantea', 'Latin' => 'Carnegia_gigantea', 14 => NULL, 'MottoURL' => NULL, 15 => NULL, 'Language' => NULL, 16 => NULL, 'Motto' => NULL, 17 => 'us-az', 'ID' => 'us-az', 18 => 'Flower', 19 => '
    And this is what I got for var_dump. (I inserted "Hello World" to separate var_export from var_dump. However, I wound up with several blocks of code for var_dump. They look almost identical.)

    Code:
    array(38) { [0]=> string(4) "3160" ["N"]=> string(4) "3160" [1]=> string(5) "us-az" ["GID"]=> string(5) "us-az" [2]=> string(12) "Arizona/Flag" ["URL"]=> string(12) "Arizona/Flag" [3]=> string(4) "Flag" ["PostURL"]=> string(4) "Flag" [4]=> string(26) "Arizona’s State Flag" ["Title"]=> string(26) "Arizona’s State Flag" [5]=> string(1) "3" ["MyKind2"]=> string(1) "3" [6]=> string(4) "flag" ["DesigGen"]=> string(4) "flag" [7]=> string(3) "Vex" ["DesigGroup"]=> string(3) "Vex" [8]=> string(0) "" ["Symbol"]=> string(0) "" [9]=> string(0) "" ["Desig"]=> string(0) "" [10]=> string(0) "" [11]=> string(4) "1917" ["Date"]=> string(4) "1917" [12]=> string(0) "" ["Common"]=> string(0) "" [13]=> string(13) "Olea_europaea" ["Latin"]=> string(13) "Olea_europaea" [14]=> NULL ["MottoURL"]=> NULL [15]=> NULL ["Language"]=> NULL [16]=> NULL ["Motto"]=> NULL [17]=> string(5) "us-az" ["ID"]=> string(5) "us-az" [18]=> string(4) "Flag" [19]=> string(0) "" ["Article"]=> string(0) "" } array ( 0 => '3161', 'N' => '3161', 1 => 'us-az', 'GID' => 'us-az', 2 => 'Arizona/Seal', 'URL' => 'Arizona/Seal', 3 => 'Seal', 'PostURL' => 'Seal', 4 => 'Arizona’s State Seal', 'Title' => 'Arizona’s State Seal', 5 => '3', 'MyKind2' => '3', 6 => 'seal', 'DesigGen' => 'seal', 7 => 'Vex', 'DesigGroup' => 'Vex', 8 => '', 'Symbol' => '', 9 => '', 'Desig' => '', 10 => '', 11 => '1911', 'Date' => '1911', 12 => '', 'Common' => '', 13 => 'Olea_europaea', 'Latin' => 'Olea_europaea', 14 => NULL, 'MottoURL' => NULL, 15 => NULL, 'Language' => NULL, 16 => NULL, 'Motto' => NULL, 17 => 'us-az', 'ID' => 'us-az', 18 => 'Seal', 19 => '', 'Article' => '', )
    
    Hello World!
    
    array(38) { [0]=> string(4) "3161" ["N"]=> string(4) "3161" [1]=> string(5) "us-az" ["GID"]=> string(5) "us-az" [2]=> string(12) "Arizona/Seal" ["URL"]=> string(12) "Arizona/Seal" [3]=> string(4) "Seal" ["PostURL"]=> string(4) "Seal" [4]=> string(26) "Arizona’s State Seal" ["Title"]=> string(26) "Arizona’s State Seal" [5]=> string(1) "3" ["MyKind2"]=> string(1) "3" [6]=> string(4) "seal" ["DesigGen"]=> string(4) "seal" [7]=> string(3) "Vex" ["DesigGroup"]=> string(3) "Vex" [8]=> string(0) "" ["Symbol"]=> string(0) "" [9]=> string(0) "" ["Desig"]=> string(0) "" [10]=> string(0) "" [11]=> string(4) "1911" ["Date"]=> string(4) "1911" [12]=> string(0) "" ["Common"]=> string(0) "" [13]=> string(13) "Olea_europaea" ["Latin"]=> string(13) "Olea_europaea" [14]=> NULL ["MottoURL"]=> NULL [15]=> NULL ["Language"]=> NULL [16]=> NULL ["Motto"]=> NULL [17]=> string(5) "us-az" ["ID"]=> string(5) "us-az" [18]=> string(4) "Seal" [19]=> string(0) "" ["Article"]=> string(0) "" } array ( 0 => '3162', 'N' => '3162', 1 => 'us-az', 'GID' => 'us-az', 2 => 'Arizona/Nickname', 'URL' => 'Arizona/Nickname', 3 => 'Nickname', 'PostURL' => 'Nickname', 4 => 'Arizona’s Nicknames', 'Title' => 'Arizona’s Nicknames', 5 => '3', 'MyKind2' => '3', 6 => 'nickname', 'DesigGen' => 'nickname', 7 => 'Top', 'DesigGroup' => 'Top', 8 => 'The Grand Canyon State', 'Symbol' => 'The Grand Canyon State', 9 => '', 'Desig' => '', 10 => 'The Grand Canyon State', 11 => '', 'Date' => '', 12 => NULL, 'Common' => NULL, 13 => NULL, 'Latin' => NULL, 14 => NULL, 'MottoURL' => NULL, 15 => NULL, 'Language' => NULL, 16 => NULL, 'Motto' => NULL, 17 => 'us-az', 'ID' => 'us-az', 18 => 'Nickname', 19 => '', 'Article' => '', )
    
    Hello World!
    
    array(38) { [0]=> string(4) "3162" ["N"]=> string(4) "3162" [1]=> string(5) "us-az" ["GID"]=> string(5) "us-az" [2]=> string(16) "Arizona/Nickname" ["URL"]=> string(16) "Arizona/Nickname" [3]=> string(8) "Nickname" ["PostURL"]=> string(8) "Nickname" [4]=> string(25) "Arizona’s Nicknames" ["Title"]=> string(25) "Arizona’s Nicknames" [5]=> string(1) "3" ["MyKind2"]=> string(1) "3" [6]=> string(8) "nickname" ["DesigGen"]=> string(8) "nickname" [7]=> string(3) "Top" ["DesigGroup"]=> string(3) "Top" [8]=> string(22) "The Grand Canyon State" ["Symbol"]=> string(22) "The Grand Canyon State" [9]=> string(0) "" ["Desig"]=> string(0) "" [10]=> string(22) "The Grand Canyon State" [11]=> string(0) "" ["Date"]=> string(0) "" [12]=> NULL ["Common"]=> NULL [13]=> NULL ["Latin"]=> NULL [14]=> NULL ["MottoURL"]=> NULL [15]=> NULL ["Language"]=> NULL [16]=> NULL ["Motto"]=> NULL [17]=> string(5) "us-az" ["ID"]=> string(5) "us-az" [18]=> string(8) "Nickname" [19]=> string(0) "" ["Article"]=> string(0) "" } array ( 0 => '3163', 'N' => '3163', 1 => 'us-az', 'GID' => 'us-az', 2 => 'Arizona/Motto', 'URL' => 'Arizona/Motto', 3 => 'Motto', 'PostURL' => 'Motto', 4 => 'Arizona’s State Motto', 'Title' => 'Arizona’s State Motto', 5 => '3', 'MyKind2' => '3', 6 => 'motto', 'DesigGen' => 'motto', 7 => 'Top', 'DesigGroup' => 'Top', 8 => 'Ditat Deus', 'Symbol' => 'Ditat Deus', 9 => '', 'Desig' => '', 10 => 'Ditat Deus', 11 => '1864', 'Date' => '1864', 12 => NULL, 'Common' => NULL, 13 => NULL, 'Latin' => NULL, 14 => 'Arizona/Motto', 'MottoURL' => 'Arizona/Motto', 15 => 'Latin', 'Language' => 'Latin', 16 => 'Ditat_Deus', 'Motto' => 'Ditat_Deus', 17 => 'us-az', 'ID' => 'us-az', 18 => 'Motto', 19 => '', 'Article' => '', )
    
    Hello World!
    
    array(38) { [0]=> string(4) "3163" ["N"]=> string(4) "3163" [1]=> string(5) "us-az" ["GID"]=> string(5) "us-az" [2]=> string(13) "Arizona/Motto" ["URL"]=> string(13) "Arizona/Motto" [3]=> string(5) "Motto" ["PostURL"]=> string(5) "Motto" [4]=> string(27) "Arizona’s State Motto" ["Title"]=> string(27) "Arizona’s State Motto" [5]=> string(1) "3" ["MyKind2"]=> string(1) "3" [6]=> string(5) "motto" ["DesigGen"]=> string(5) "motto" [7]=> string(3) "Top" ["DesigGroup"]=> string(3) "Top" [8]=> string(19) "Ditat Deus" ["Symbol"]=> string(19) "Ditat Deus" [9]=> string(0) "" ["Desig"]=> string(0) "" [10]=> string(19) "Ditat Deus" [11]=> string(4) "1864" ["Date"]=> string(4) "1864" [12]=> NULL ["Common"]=> NULL [13]=> NULL ["Latin"]=> NULL [14]=> string(13) "Arizona/Motto" ["MottoURL"]=> string(13) "Arizona/Motto" [15]=> string(5) "Latin" ["Language"]=> string(5) "Latin" [16]=> string(10) "Ditat_Deus" ["Motto"]=> string(10) "Ditat_Deus" [17]=> string(5) "us-az" ["ID"]=> string(5) "us-az" [18]=> string(5) "Motto" [19]=> string(0) "" ["Article"]=> string(0) "" } array ( 0 => '3164', 'N' => '3164', 1 => 'us-az', 'GID' => 'us-az', 2 => 'Arizona/Song', 'URL' => 'Arizona/Song', 3 => 'Song', 'PostURL' => 'Song', 4 => 'Arizona’s State Anthem', 'Title' => 'Arizona’s State Anthem', 5 => '3', 'MyKind2' => '3', 6 => 'song', 'DesigGen' => 'song', 7 => 'Top', 'DesigGroup' => 'Top', 8 => 'Arizona March Song', 'Symbol' => 'Arizona March Song', 9 => 'Anthem', 'Desig' => 'Anthem', 10 => 'Arizona March Song', 11 => '1919', 'Date' => '1919', 12 => NULL, 'Common' => NULL, 13 => NULL, 'Latin' => NULL, 14 => NULL, 'MottoURL' => NULL, 15 => NULL, 'Language' => NULL, 16 => NULL, 'Motto' => NULL, 17 => 'us-az', 'ID' => 'us-az', 18 => 'Song', 19 => '', 'Article' => '', )
    
    Hello World!
    
    array(38) { [0]=> string(4) "3164" ["N"]=> string(4) "3164" [1]=> string(5) "us-az" ["GID"]=> string(5) "us-az" [2]=> string(12) "Arizona/Song" ["URL"]=> string(12) "Arizona/Song" [3]=> string(4) "Song" ["PostURL"]=> string(4) "Song" [4]=> string(28) "Arizona’s State Anthem" ["Title"]=> string(28) "Arizona’s State Anthem" [5]=> string(1) "3" ["MyKind2"]=> string(1) "3" [6]=> string(4) "song" ["DesigGen"]=> string(4) "song" [7]=> string(3) "Top" ["DesigGroup"]=> string(3) "Top" [8]=> string(18) "Arizona March Song" ["Symbol"]=> string(18) "Arizona March Song" [9]=> string(6) "Anthem" ["Desig"]=> string(6) "Anthem" [10]=> string(18) "Arizona March Song" [11]=> string(4) "1919" ["Date"]=> string(4) "1919" [12]=> NULL ["Common"]=> NULL [13]=> NULL ["Latin"]=> NULL [14]=> NULL ["MottoURL"]=> NULL [15]=> NULL ["Language"]=> NULL [16]=> NULL ["Motto"]=> NULL [17]=> string(5) "us-az" ["ID"]=> string(5) "us-az" [18]=> string(4) "Song" [19]=> string(0) "" ["Article"]=> string(0) "" } array ( 0 => '3165', 'N' => '3165', 1 => 'us-az', 'GID' => 'us-az', 2 => 'Arizona/Song2', 'URL' => 'Arizona/Song2', 3 => 'Song2', 'PostURL' => 'Song2', 4 => 'Arizona’s Alternate State Anthem', 'Title' => 'Arizona’s Alternate State Anthem', 5 => '3', 'MyKind2' => '3', 6 => 'song', 'DesigGen' => 'song', 7 => 'Top', 'DesigGroup' => 'Top', 8 => 'Arizona', 'Symbol' => 'Arizona', 9 => 'Alternate Anthem', 'Desig' => 'Alternate Anthem', 10 => 'Arizona', 11 => '1981', 'Date' => '1981', 12 => NULL, 'Common' => NULL, 13 => NULL, 'Latin' => NULL, 14 => NULL, 'MottoURL' => NULL, 15 => NULL, 'Language' => NULL, 16 => NULL, 'Motto' => NULL, 17 => 'us-az', 'ID' => 'us-az', 18 => 'Song2', 19 => '', 'Article' => '', )
    
    Hello World!
    
    array(38) { [0]=> string(4) "3165" ["N"]=> string(4) "3165" [1]=> string(5) "us-az" ["GID"]=> string(5) "us-az" [2]=> string(13) "Arizona/Song2" ["URL"]=> string(13) "Arizona/Song2" [3]=> string(5) "Song2" ["PostURL"]=> string(5) "Song2" [4]=> string(38) "Arizona’s Alternate State Anthem" ["Title"]=> string(38) "Arizona’s Alternate State Anthem" [5]=> string(1) "3" ["MyKind2"]=> string(1) "3" [6]=> string(4) "song" ["DesigGen"]=> string(4) "song" [7]=> string(3) "Top" ["DesigGroup"]=> string(3) "Top" [8]=> string(7) "Arizona" ["Symbol"]=> string(7) "Arizona" [9]=> string(16) "Alternate Anthem" ["Desig"]=> string(16) "Alternate Anthem" [10]=> string(7) "Arizona" [11]=> string(4) "1981" ["Date"]=> string(4) "1981" [12]=> NULL ["Common"]=> NULL [13]=> NULL ["Latin"]=> NULL [14]=> NULL ["MottoURL"]=> NULL [15]=> NULL ["Language"]=> NULL [16]=> NULL ["Motto"]=> NULL [17]=> string(5) "us-az" ["ID"]=> string(5) "us-az" [18]=> string(5) "Song2" [19]=> string(0) "" ["Article"]=> string(0) "" } array ( 0 => '3166', 'N' => '3166', 1 => 'us-az', 'GID' => 'us-az', 2 => 'Arizona/Flower', 'URL' => 'Arizona/Flower', 3 => 'Flower', 'PostURL' => 'Flower', 4 => 'Arizona’s State Flower', 'Title' => 'Arizona’s State Flower', 5 => '3', 'MyKind2' => '3', 6 => 'flower', 'DesigGen' => 'flower', 7 => 'Plants', 'DesigGroup' => 'Plants', 8 => 'saguaro cactus blossom', 'Symbol' => 'saguaro cactus blossom', 9 => '', 'Desig' => '', 10 => 'saguaro cactus blossom', 11 => '1931', 'Date' => '1931', 12 => 'saguaro cactus blossom', 'Common' => 'saguaro cactus blossom', 13 => 'Carnegia_gigantea', 'Latin' => 'Carnegia_gigantea', 14 => NULL, 'MottoURL' => NULL, 15 => NULL, 'Language' => NULL, 16 => NULL, 'Motto' => NULL, 17 => 'us-az', 'ID' => 'us-az', 18 => 'Flower', 19 => '
    P.S. Thanks for the code; I can see how it might be useful for troubleshooting. For example, I found one value that shouldn't even be listed - Olea_europea.

  8. #8
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Ok, I'm glad you've learned how to really peer inside your array using var_dump(), you will use this ALL THE TIME not only to look at arrays, but to check the value and the type of all kinds of variables that you create.

    The reason to use var_export is so that instead of typing out your array by hand, I can just copy and paste it and then start using it. That means you will get help faster when asking Qs about arrays.

    I indented this first array, is this really what you expected from your db query? The next 4 are there too.

    You have both numerical keys and string keys containing the same data?
    PHP Code:
    // this is your result set, I think
    $rows =
    array( 
    =>
     array ( 
    => '3160',
     
    'N' => '3160'
    => 'us-az',
    'GID' => 'us-az'
    => 'Arizona/Flag'
    'URL' => 'Arizona/Flag'
    => 'Flag'
    'PostURL' => 'Flag'
    => 'Arizonas State Flag'
    'Title' => 'Arizonas State Flag'
    => '3'
    'MyKind2' => '3'
    => 'flag',
     
    'DesigGen' => 'flag'
    => 'Vex'
    'DesigGroup' => 'Vex'
    => ''
    'Symbol' => ''
    => ''
    'Desig' => ''
    10 => ''
    11 => '1917'
    'Date' => '1917'
    12 => '',
     
    'Common' => ''
    13 => 'Olea_europaea',
    'Latin' => 'Olea_europaea'
    14 => NULL
    'MottoURL' => NULL
    15 => NULL
    'Language' => NULL
    16 => NULL
    'Motto' => NULL
    17 => 'us-az'
    'ID' => 'us-az'
    18 => 'Flag'
    19 => ''
    'Article' => '', ),

    => 

    array ( 
    => '3161''N' => '3161'=> 'us-az''GID' => 'us-az'=> 'Arizona/Seal''URL' => 'Arizona/Seal'=> 'Seal''PostURL' => 'Seal'=> 'Arizona State Seal'=> '3''MyKind2' => '3'=> 'seal''DesigGen' => 'seal'=> 'Vex''DesigGroup' => 'Vex'=> '''Symbol' => ''=> '''Desig' => ''10 => ''11 => '1911''Date' => '1911'12 => '''Common' => ''13 => 'Olea_europaea''Latin' => 'Olea_europaea'14 => NULL'MottoURL' => NULL15 => NULL'Language' => NULL16 => NULL'Motto' => NULL17 => 'us-az''ID' => 'us-az'18 => 'Seal'
    19 => '''Article' => '', ) 
    =>
    array ( 
    => '3162''N' => '3162'=> 'us-az''GID' => 'us-az'=> 'Arizona/Nickname''URL' => 'Arizona/Nickname'=> 'Nickname''PostURL' => 'Nickname'=> 'Arizonas Nicknames''Title' => 'Arizona Nicknames'=> '3''MyKind2' => '3'=> 'nickname''DesigGen' => 'nickname'=> 'Top''DesigGroup' => 'Top'=> 'The Grand Canyon State''Symbol' => 'The Grand Canyon State'=> '''Desig' => ''10 => 'The Grand Canyon State'11 => '''Date' => ''12 => NULL'Common' => NULL13 => NULL'Latin' => NULL14 => NULL'MottoURL' => NULL15 => NULL'Language' => NULL16 => NULL'Motto' => NULL17 => 'us-az''ID' => 'us-az'18 => 'Nickname'19 => '''Article' => '', ) 
    3=>
    array ( 
    => '3163''N' => '3163'=> 'us-az''GID' => 'us-az'=> 'Arizona/Motto''URL' => 'Arizona/Motto'=> 'Motto''PostURL' => 'Motto'=> 'ArizonaState Motto''Title' => 'Arizonas State Motto'=> '3''MyKind2' => '3'=> 'motto''DesigGen' => 'motto'=> 'Top''DesigGroup' => 'Top'=> 'Ditat Deus''Symbol' => 'Ditat Deus'=> '''Desig' => ''10 => 'Ditat Deus'11 => '1864''Date' => '1864'12 => NULL'Common' => NULL13 => NULL'Latin' => NULL14 => 'Arizonas Motto''MottoURL' => 'Arizona/Motto'15 => 'Latin''Language' => 'Latin'16 => 'Ditat_Deus''Motto' => 'Ditat_Deus'17 => 'us-az''ID' => 'us-az'18 => 'Motto'19 => '''Article' => '', ) 
    ,
    =>
    array ( 
    => '3164''N' => '3164'=> 'us-az''GID' => 'us-az'=> 'Arizona/Song''URL' => 'Arizona/Song'=> 'Song''PostURL' => 'Song'=> 'Arizona State Anthem''Title' => 'Arizonas State Anthem'=> '3''MyKind2' => '3'=> 'song''DesigGen' => 'song'=> 'Top''DesigGroup' => 'Top'=> 'Arizona March Song''Symbol' => 'Arizona March Song'=> 'Anthem''Desig' => 'Anthem'10 => 'Arizona March Song'11 => '1919''Date' => '1919'12 => NULL'Common' => NULL13 => NULL'Latin' => NULL14 => NULL'MottoURL' => NULL15 => NULL'Language' => NULL16 => NULL'Motto' => NULL17 => 'us-az''ID' => 'us-az'18 => 'Song'19 => '''Article' => '', ) 
    =>
    array ( 
    => '3165''N' => '3165'=> 'us-az''GID' => 'us-az'=> 'Arizona/Song2''URL' => 'Arizona/Song2'=> 'Song2''PostURL' => 'Song2'=> 'Arizonas Alternate State Anthem''Title' => 'Arizonas Alternate State Anthem'=> '3''MyKind2' => '3'=> 'song''DesigGen' => 'song'=> 'Top''DesigGroup' => 'Top'=> 'Arizona''Symbol' => 'Arizona'=> 'Alternate Anthem''Desig' => 'Alternate Anthem'10 => 'Arizona'11 => '1981''Date' => '1981'12 => NULL'Common' => NULL13 => NULL'Latin' => NULL14 => NULL'MottoURL' => NULL15 => NULL'Language' => NULL16 => NULL'Motto' => NULL17 => 'us-az''ID' => 'us-az'18 => 'Song2'19 => '''Article' => '', ) 
    );

    var_dump($rows); 
    Are these typical rows?

  9. #9
    SitePoint Addict
    Join Date
    Jan 2012
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That looks 95% correct. It displays information for an article about Arizona's state flag at Arizona/Flag, row #3160 in my database table, and flags are correctly classified as DesigGroup = "Vex", DesigGen = "flag." Arizona's flag was adopted in 1917.

    However, I'm not sure why the 12th value, "Common," is there, and the last one - "Olea_europea" - doesn't belong there at all.

    Part of the problem is that I've joined several tables and am displaying information for symbols that are very different. For example, national flowers and birds have both common names and scientific names, while flags have neither.

    But the data is displaying surprisingly well in general. I just have a few modifications to make.


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
  •