SitePoint Sponsor

User Tag List

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

    Need to display data in my table, not outside.

    This is another going-back-to-square-one thread. With a lot of help, I hammered out a dynamic table query that seems to do what I want it to. The only catch is that it displays the data outside the table, and I can't figure out how to make it display IN the table.

    I also have a second query that I think might work, also...

    PHP Code:
    /*
    $res = mysql_query("SELECT Area, Class, `Order` FROM symbols ORDER BY `Order`");
        while ($row = mysql_fetch_row($res))

    $resultArray = array();

    while($row = mysql_fetch_assoc($result)) {
      $resultArray[$row['mammalorder']][] = $row['area'];

    foreach(array_keys($resultArray) as $mammalorder) {
        // example output
    //    echo implode(', ', $resultArray[$mammalorder]).' | ' $mammalorder;
    }
    */ 
    But, again, I can't make it display IN the table.

    Can someone help me straighten this out once and for all? I pasted the entire source code below. It includes a lot of junk, but I left BIG spaces before the two most important sections - the query and the table rows.

    Thanks!

    PHP Code:
    <?php
    switch ($Animals['SymClass']) {
    case 
    'animals':
    $colors = array( '#f4eec2''' );
    $n=0;
    $size=count($colors);
    break;
    case 
    'plants':
    $colors = array( '#80ff80''''#bfffbf''' );
    $n=0;
    $size=count($colors);
    break;
    default:
    break;
    }

    switch (
    $Animals['SymClass']) {
    case 
    'animals':
    $BG '#900';
    $n=0;
    $size=count($colors);
    break;
    case 
    'plants':
    $BG '#090';
    $n=0;
    $size=count($colors);
    break;
    default:
    break;
    }











    $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':
    // 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>' $tempArray[$counter] . '</td>';
    $block .= '<td>' $tempArray['$counterI'] . '</td>';
    $block .= '</tr>';


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

    ?>

  2. #2
    *munch munch* killerkooki's Avatar
    Join Date
    Sep 2004
    Location
    Singapore
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Code:
    <?php
    switch ($Animals['SymClass']) {
        case 
    'animals':
            
    $colors = array( '#f4eec2''' );
            
    $n=0;
            
    $size=count($colors);
            break;
        case 
    'plants':
            
    $colors = array( '#80ff80''''#bfffbf''' );
            
    $n=0;
            
    $size=count($colors);
            break;
        default:
        break;
        }

    switch (
    $Animals['SymClass']) {
        case 
    'animals':
            
    $BG '#900';
            
    $n=0;
            
    $size=count($colors);
            break;
        case 
    'plants':
            
    $BG '#090';
            
    $n=0;
            
    $size=count($colors);
            break;
        default:
        break;
        }

    $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;
        }

    $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':
        
    // 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;

    /*
    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>';
        }
    */

    for ($counter 0$counter count($orderArray); $counter++) {
            
    // 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>';
        
    $tempArray = array();
        
    $tempArray $placeArray[$counter];
        for (
    $counterI 0$counterI count($tempArray); $counterI++) {
            if (
    $counterI == 0)
                
    $block .= $tempArray[$counterI];
            else
                
    $block .= ', ' $tempArray[$counterI];
            }

        
    $block .= '</td>';
        
    $block .= '</tr>';


        
    $i++;
        }

    $block .= "</tbody></table>";
        
    echo 
    $block;

    ?>
    I am not sure if you can get your alternating colours and that sort of thing going correctly though...

  3. #3
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow, that's weird... It displays correctly (except with no table cell colors) for a few seconds, then the place names suddenly disappear and are replaced by "NaN."

  4. #4
    *munch munch* killerkooki's Avatar
    Join Date
    Sep 2004
    Location
    Singapore
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you running some javascript in the page to replace content or something?

  5. #5
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by killerkooki
    Are you running some javascript in the page to replace content or something?
    I have some JavaScript includes for running various functions, like pop-ups. But I don't think there's anything that relates to my database.

  6. #6
    SitePoint Addict fesh's Avatar
    Join Date
    Jan 2005
    Location
    Jackson, New Jersey
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    to my knowledge, the only reason NaN comes up is because Javascript sent a value that is Not a Number. I've never heard of PHP ever returning NaN. So maybe check those JavaScripts.
    Fesh
    imagine what it's going to be like

  7. #7
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fesh
    to my knowledge, the only reason NaN comes up is because Javascript sent a value that is Not a Number. I've never heard of PHP ever returning NaN. So maybe check those JavaScripts.
    OK, I just nixed all the JavaScripts in my head section, but it still displays NaN. I don't think I have any other JavaScripts on my include pages.

    Thanks.

  8. #8
    *munch munch* killerkooki's Avatar
    Join Date
    Sep 2004
    Location
    Singapore
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any rollovers that are meant to replace the cell background colours or such?
    As fesh said, and as far I have encounted, NaN occurred only when using Javascript.

  9. #9
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by killerkooki
    Any rollovers that are meant to replace the cell background colours or such?
    As fesh said, and as far I have encounted, NaN occurred only when using Javascript.
    Ah, it looks like there may be a conflict with my body tag...

    PHP Code:
    <body $mybody 'class="body'$topstuff['IDParent'] .'" id="body'$mycode2 .'" onload="P7_swapClass(0,\'none\',\'showIt\',\'hideIt\',\'div\');typeWriter(\'quote\',50);initialize()"'
    I wonder why it would affect one column and not the other.

  10. #10
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops, sorry...it looks like the problem is with one of the JavaScripts after all, not the body tag. I was confused with the delayed reaction combined with my page taking a long time to save.


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
  •