SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 33 of 33
  1. #26
    *munch munch* killerkooki's Avatar
    Join Date
    Sep 2004
    Location
    Singapore
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $block '<table>';
    for (
    $counter 0$counter count($orderArray); $counter++) {
        
    $block .= '<tr><td>' $orderArray[$counter] . '</td>';
        
    $tempArray = array();
        
    $tempArray $placeArray[$counter];
        for (
    $counterI 0$counterI $count($tempArray); $counterI++) {
            if (
    $counterI == 0)
                
    $block .= $tempArray[$counterI];
            else
                
    $block .= ', ' $tempArray[$counterI];
            }
        
    $block .= '</tr>';
        }
    $block .= '</table>'

    You can remove the following:
    PHP Code:
    for ($counter 0$counter count($orderArray); $counter++) {
        echo 
    $orderArray[$counter] . ': ';
        
    $tempArray = array();
        
    $tempArray $placeArray[$counter];
        for (
    $counterI 0$counterI $count($tempArray); $counterI++) {
            if (
    $counterI == 0)
                echo 
    $tempArray[$counterI];
            else
                echo 
    ', ' $tempArray[$counterI];
            }
        echo 
    '<br>';
        } 
    This is a part from what I posted earlier and it is just to print out the values. So you no longer require it.

    Just put the snippet at the top, in the are where you need to create the table.

  2. #27
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops, sorry, I made a mistake. It's not really working correctly. For example, the first row begins...

    Lepidoptera (butterflies): Afghanistan, Albania, Algeria, American Samoa, Andorra, Angola, Anguilla, Armenia, Aruba, Ashmore and Cartier Islands,

    Yet butterflies aren't associated with any of these nations in my database. It appears to be including a row for every nation, regardless of what data its row contains.

    I thought "WHERE Class = 'myname'" would solve that problem. I don't know why it doesn't.

    Thanks.

  3. #28
    *munch munch* killerkooki's Avatar
    Join Date
    Sep 2004
    Location
    Singapore
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My bad again...
    PHP Code:
    $res mysql_query("SELECT DISTINCT(`Order`) FROM symbols WHERE Class = '$myname'");
    $orderArray = array();
    while (
    $row mysql_fetch_row($res)) {
        
    //Dump all the orders into an array
        
    $orderArray[] = $row[0];
        }

    $placeArray = array();
    for (
    $counter 0$counter count($orderArray); $counter++) {
        
    $res mysql_query("SELECT Area FROM symbols WHERE `Order`='$orderArray[$counter]'");
        
    $placeArrayForOrder = array();
        while (
    $row mysql_fetch_row($res)) {
            
    //Dump all the places into an array
            
    $placeArrayForOrder[] = $row[0];
            }
        
    $placeArray[] = $placeArrayForOrder;
        } 
    I put the wrong array for the second condition to get the Area. Hope that's the last of the mistakes... this is starting to look embarrassing...

  4. #29
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, now it's displaying perfectly - just outside the table. How should I change this to make it display data inside table cells? Thanks.

    PHP Code:
    $block .= '<tr>';
    $block .= '<td>' $orderArray[$counter] . '</td>';
    $block .= '<td>' $orderArray[$counterI] . '</td>';
    $block .= '</tr>'

  5. #30
    *munch munch* killerkooki's Avatar
    Join Date
    Sep 2004
    Location
    Singapore
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post the latest code you have?
    I think its pasting outside because of other statements that are either opening or closing the HTML tables... So it'll be easier for me to see it with the full code.

  6. #31
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by killerkooki
    Can you post the latest code you have?
    I think its pasting outside because of other statements that are either opening or closing the HTML tables... So it'll be easier for me to see it with the full code.
    Sorry about all the junk. I deleted the first two PHP switches, but I thought I'd better leave everything else in, in case I made some sort of mistake I haven't noticed. Thanks.

    PHP Code:
    <?php
    $res 
    mysql_query("SELECT DISTINCT(`Order`) FROM symbols WHERE Class = '$myname'");
    $orderArray = array();
    while (
    $row mysql_fetch_row($res)) {
        
    //Dump all the orders into an array
        
    $orderArray[] = $row[0];
        }

    $placeArray = array();
    for (
    $counter 0$counter count($orderArray); $counter++) {
        
    $res mysql_query("SELECT Area FROM symbols WHERE `Order`='$orderArray[$counter]'");
        
    $placeArrayForOrder = array();
        while (
    $row mysql_fetch_row($res)) {
            
    //Dump all the places into an array
            
    $placeArrayForOrder[] = $row[0];
            }
        
    $placeArray[] = $placeArrayForOrder;
        }
    for (
    $counter 0$counter count($orderArray); $counter++) {
        echo 
    $orderArray[$counter] . ': ';
        
    $tempArray = array();
         
    $tempArray $placeArray[$counter];
        for (
    $counterI 0$counterI count($tempArray); $counterI++) {
            if (
    $counterI == 0)
                echo 
    $tempArray[$counterI];
            else
                echo 
    ', ' $tempArray[$counterI];
            }
        echo 
    '<br>';
        }


    $block "<table class=\"sortphp_ref\" id=\"Table2\" style=\"margin: 0px auto 25px; border-bottom: 1px solid #000; font-size: 85%;\">";
    $block .="<thead>
    <tr><th style=\"background: #666; color: #fff;\">Places</th>
    <th style=\"background: 
    $BG; color: #fff;\">Orders</th></tr>
    </thead>
    <tbody>"
    ;
        
        
    // Look at this as rows & columns of a table,
        // the colors will alternate just like to do in this list.
    switch ($Animals['SymClass']) {
    case 
    'animals':
    8// INTERNAL SWITCH
    switch ($Animals['ClassCommon']) {
    case 
    'fishes':
    $color_sets = array(
     array(
    '#eee''#cff'),
     array(
    '',''),
        );
    break;
    default:
    $color_sets = array(
     array(
    '#eee''#f4eec2'),
     array(
    '',''),
        );
    break;
    }
    // END INTERNAL SWITCH
    break;

    case 
    'plants':
    $color_sets = array(
     array(
    '#eee''#80ff80'),
     array(
    '',''),
     array(
    '#eee''#bfffbf'),
     array(
    '',''),
        );
    break;
    default:
    break;
    }
        
    // Count colors, used to determine which color set to use.
        
    $cset_size sizeof($color_sets);
        
        
    $i 0;
        while (
    $row mysql_fetch_array ($res)) {
            
    // Determine color set
            
    $c $i $cset_size;

    switch (
    $Animals['SymClass']) {
    case 
    'animals':
    $LinkSymbol '/animals/' strtolower($row["ClassCommon"]) . '/' strtolower(substr($row["Order"],0,3)) . '/';
    break;
    case 
    'plants':
    $LinkSymbol '/plants/' strtolower($row["ClassCommon"]) . '/' strtolower(substr($row["Order"],0,3)) . '/';
    break;
    default:
    break;
    }

    $block .= '<tr>';
    $block .= '<td>' $orderArray[$counter] . '</td>';
    $block .= '<td>' $orderArray[$counterI] . '</td>';
    $block .= '</tr>'


      
    $i++;
        }
      
    $block .= "</tbody></table>";
        
        echo 
    $block;
    ?>

  7. #32
    *munch munch* killerkooki's Avatar
    Join Date
    Sep 2004
    Location
    Singapore
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $res 
    mysql_query("SELECT DISTINCT(`Order`) FROM symbols WHERE Class = '$myname'");
    $orderArray = array();
    while (
    $row mysql_fetch_row($res)) {
        
    //Dump all the orders into an array
        
    $orderArray[] = $row[0];
        }

    $placeArray = array();
    for (
    $counter 0$counter count($orderArray); $counter++) {
        
    $res mysql_query("SELECT Area FROM symbols WHERE `Order`='$orderArray[$counter]'");
        
    $placeArrayForOrder = array();
        while (
    $row mysql_fetch_row($res)) {
            
    //Dump all the places into an array
            
    $placeArrayForOrder[] = $row[0];
            }
        
    $placeArray[] = $placeArrayForOrder;
        }
    /*
    for ($counter = 0; $counter < count($orderArray); $counter++) {
        echo $orderArray[$counter] . ': ';
        $tempArray = array();
         $tempArray = $placeArray[$counter];
        for ($counterI = 0; $counterI < count($tempArray); $counterI++) {
            if ($counterI == 0)
                echo $tempArray[$counterI];
            else
                echo ', ' . $tempArray[$counterI];
            }
        echo '<br>';
        }
    */

    $block "<table class=\"sortphp_ref\" id=\"Table2\" style=\"margin: 0px auto 25px; border-bottom: 1px solid #000; font-size: 85%;\">";
    $block .="<thead>
    <tr><th style=\"background: #666; color: #fff;\">Places</th>
    <th style=\"background: 
    $BG; color: #fff;\">Orders</th></tr>
    </thead>
    <tbody>"
    ;
        
        
    // Look at this as rows & columns of a table,
        // the colors will alternate just like to do in this list.
    switch ($Animals['SymClass']) {
    case 
    'animals':
    8// INTERNAL SWITCH
    switch ($Animals['ClassCommon']) {
    case 
    'fishes':
    $color_sets = array(
    array(
    '#eee''#cff'),
    array(
    '',''),
        );
    break;
    default:
    $color_sets = array(
    array(
    '#eee''#f4eec2'),
    array(
    '',''),
        );
    break;
    }
    // END INTERNAL SWITCH
    break;

    case 
    'plants':
    $color_sets = array(
    array(
    '#eee''#80ff80'),
    array(
    '',''),
    array(
    '#eee''#bfffbf'),
    array(
    '',''),
        );
    break;
    default:
    break;
    }
        
    // Count colors, used to determine which color set to use.
        
    $cset_size sizeof($color_sets);
        
        
    $i 0;
        while (
    $row mysql_fetch_array ($res)) {
            
    // Determine color set
            
    $c $i $cset_size;

    switch (
    $Animals['SymClass']) {
    case 
    'animals':
    $LinkSymbol '/animals/' strtolower($row["ClassCommon"]) . '/' strtolower(substr($row["Order"],0,3)) . '/';
    break;
    case 
    'plants':
    $LinkSymbol '/plants/' strtolower($row["ClassCommon"]) . '/' strtolower(substr($row["Order"],0,3)) . '/';
    break;
    default:
    break;
    }

    /*
    $block .= '<tr>';
    $block .= '<td>' . $orderArray[$counter] . '</td>';
    $block .= '<td>' . $orderArray[$counterI] . '</td>';
    $block .= '</tr>';
    */

    for ($counter 0$counter count($orderArray); $counter++) {
        
    $block .= '<tr><td>' $orderArray[$counter] . '</td><td>';
        
    $tempArray = array();
        
    $tempArray $placeArray[$counter];
        for (
    $counterI 0$counterI $count($tempArray); $counterI++) {
            if (
    $counterI == 0)
                
    $block .= $tempArray[$counterI];
            else
                
    $block .= ', ' $tempArray[$counterI];
            }
        
    $block.= '</td></tr>';


      
    $i++;
        }
      
    $block .= "</tbody></table>";
        
        echo 
    $block;
    ?>
    How's that?

  8. #33
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's weird; somehow, a numeral 8 wound up here, causing an error....

    8// INTERNAL SWITCH

    No big deal; I fixed it. Then I fixed a second error by adding a bracket - } - at the very end of the script.

    But when I preview my page, I don't see the table at all. There are no error messages, and I see all the text I've included. But there's no table. I'll play with it some more.

    Thanks.


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
  •