Jump to content

Tables


inneedofhelp

Recommended Posts

Im tring to create the second of two pages. The first page has a table that displays a row number, a count, and an error code. I want the next page to create a table by clicking on the the error code or row number. The table is suppost to diaplay the error code and all case numbers for that code. Here is an array with dummy data. In this array the counts are 3,6,10,12, the error codes are 4,5,6,7, and the case numbers are 31,41,51 for the top row, 32,42,52 for the second row and ect. The code below creates the table on the first page. Please help me create the second page. Thanks

$errcount=array(array(3,array(array(31,4),array(41,4),array(51,4))),
array(6,array(array(32,5),array(42,5),array(52,5))),
array(10,array(array(33,6),array(43,6),array(53,6))),
array(13,array(array(34,7),array(44,7),array(54,7))))

<!Set up table headings>
<html>
<table border="0" cellpadding="3">
<tr bgcolor=#CCCCCC>
<th>

</th>
<th>
# Of Events
</th>
<th>
Error Code
</th>
</tr>

<!setup table>
<? $i=0;?>
<? foreach($errcount as $C){ ?>
<tr bgcolor= <?if($i%2 == 0) {
echo "#EEEEEE";
}
else {
echo "#CCCCCC";
}?>>
<td>
<?echo $i++; ?>
</td>
<td>
<? echo $C[0]; ?>
</td>
<td>
<? echo $C[1][0][1]; ?>
</td>
</tr>
<? } ?>
</table>
</html>
Link to comment
Share on other sites

So, your data array looks something like this:

[code]Array
(
    [0] => Array
        (
            [0] => 3
            [1] => Array
                (
                    [0] => Array
                        (
                            [0] => 31
                            [1] => 4
                        )

                    [1] => Array
                        (
                            [0] => 41
                            [1] => 4
                        )

                    [2] => Array
                        (
                            [0] => 51
                            [1] => 4
                        )

                )

        )

    [1] => Array
        (
            [0] => 6
            [1] => Array
                (
                    [0] => Array
                        (
                            [0] => 32
                            [1] => 5
                        )

                    [1] => Array
                        (
                            [0] => 42
                            [1] => 5
                        )

                    [2] => Array
                        (
                            [0] => 52
                            [1] => 5
                        )

                )

        )
...[/code]

I see where the number of events is coming from, and I see where the error code is coming from. What does the first element of the sub-sub array represent...in the case of error code 5 above, the 32, 42, 52? Is that the case number?

Also, will your array always follow this format? Will the like error codes always be grouped into sub arrays like above?
Link to comment
Share on other sites

Making the assumptions that I asked about above, I think this might work for you. This will only work if your array structure remains constant.

[code]
<?php

$errcount=array(array(3,array(array(31,4),array(41,4),array(51,4))),
array(6,array(array(32,5),array(42,5),array(52,5))),
array(10,array(array(33,6),array(43,6),array(53,6))),
array(13,array(array(34,7),array(44,7),array(54,7))));

?>
<html>

<?php
if ($_GET['page'] == "next") {
    $element = $_GET['element'];
    $error = $errcount[$element];
    echo 'The following Case Numbers had error code ' . $error[1][0][1];
    echo '<table border="1" cellspacing="0" cellpadding="3"><tr><td>Case Number</td></tr>';
    
    foreach ($error[1] as $e) {
        if ($i%2 == 0) {
            $bg = "#EEEEEE";
        } else {
            $bg = "#CCCCCC";
        }
        echo '<tr bgcolor="' . $bg . '">
                
                <td>' . $e[0] . '</td>
            </tr>';
        $i++;
    }
    echo '<table>';
} else {
    echo '<table border="0" cellpadding="3">
        <tr bgcolor=#CCCCCC>
            <th></th>
            <th># Of Events</th>
            <th>Error Code</th>
        </tr>';
    $i = 0;
    foreach ($errcount as $C) {
        if ($i%2 == 0) {
            $bg = "#EEEEEE";
        } else {
            $bg = "#CCCCCC";
        }
        echo '
            <tr bgcolor="' . $bg . '">
                <td><a href="test.php?page=next&element=' . $i . '">' . $i . '</a></td>
                <td>' . $C[0] . '</td>
                <td><a href="test.php?page=next&element=' . $i . '">' . $C[1][0][1] . '</a></td>
            </tr>';
        $i++;
    }
    echo '</table>';
}

?>
</html>[/code]

Definatly one of the more complicated things I've done with arrays. This would be a lot easier, assuming you are creating the array in a previous step, if you made your array keys into something meaningful. You would better be able to delve into the array and tell where you are at and access the data more easily.
Link to comment
Share on other sites

Great Thanks. I changes things a bit and now want to make the second page sortable. I would like to be able to sort the entrys by the date as a default and by the case number, customer, and date. Here is the code.

<?php session_start();
include "reg_vars.php";
include "classes.inc.php";

//Create Sortable Column Links
$link1 = "{$_SERVER['PHP_SELF']}?sort=cna";//sort by case number
$link2 = "{$_SERVER['PHP_SELF']}?sort=cra";//sort by customer
$link3 = "{$_SERVER['PHP_SELF']}?sort=doa";//sort by date

//Determine sort order
if(isset($_GET['sort'])){

//Use existing sorting order
switch ($_GET['sort']){
case 'cna':
$order_by = 'Case_No ASC';
$link1 = "{$_SERVER['PHP_SELF']}?sort=csd";
break;
case 'cnd':
$order_by = 'Case_No DESC';
$link1 = "{$_SERVER['PHP_SELF']}?sort=csa";
break;
case 'cra':
$order_by = 'Customer ASC';
$link2 = "{$_SERVER['PHP_SELF']}?sort=crd";
break;
case 'crd':
$order_by = 'Customer DESC';
$link2 = "{$_SERVER['PHP_SELF']}?sort=cra";
break;
case 'doa':
$order_by = 'Inc_Date ASC';
$link3 = "{$_SERVER['PHP_SELF']}?sort=dod";
break;
case 'dod':
$order_by = 'Inc_Date DESC';
$link3 = "{$_SERVER['PHP_SELF']}?sort=doa";
break;
default:
$order_by = 'Inc_Date DESC';
break;
}
//$sort will be appended to the pagination links.
$sort = $_GET['sort'];
} else { //Use the default sorting order.
$order_by = 'dod';
$sort = 'dod';
}

//if (!isset($_SESSION['errcount'])) {
$qdb = "test";
$qaction = "select";
$qfieldsarray = array("Case_No", "ErrorCodes", "Inc_Date", "Customer", "Logs");
$qsort = "ErrorCodes";
$active = new QueryClass2($qdb,"active",$qaction,$qfieldsarray,$qconds,$qstartdate,$qenddate,$qsort,$qlim);
$resolved = new QueryClass2($qdb,"resolved",$qaction,$qfieldsarray,$qconds,$qstartdate,$qenddate,$qsort,$qlim);
$active_data = $active->getData();
$resolved_data = $resolved->getData();
$data = array_merge($active_data, $resolved_data);
$c =0;
foreach($data as $s){
preg_match_all("/\w{4}/",$s["ErrorCodes"],$codes);
if(count($codes[0])>1){
foreach($codes[0] as $co ){
$data[]=array("Case_No"=>$s["Case_No"],"ErrorCodes"=>$co, "Inc_Date"=>$s["Inc_Date"], "Customer"=>$s["Customer"], "Logs"=>$s["Logs"]);
}
unset($data[$c]);
}
$c++;
}
$data = array_values($data);

$errcount = array();
foreach( $data as $s ){
$found = false;
$c = 0;
foreach( $errcount as $r ){
if(strcasecmp($s["ErrorCodes"], $r[1][0]["ErrorCodes"]) == 0 ){
$errcount[$c][1][$r[0]]=$s;
$errcount[$c][0]++;
$found = true;
}
$c++;
}
if( !$found ){
$errcount[count($errcount)]=array(1, array($s));
}
}
$m = 0;
foreach( $errcount as $err){
if($err[0] < 2 ){
unset( $errcount[$m] );
}
$m++;
}
$errcount = array_merge($errcount);
$_SESSION['errcount'] = $errcount;

//Create Second Page
if ($_GET['page'] == "next") {
$element = $_GET['element'];
$error = $_SESSION['errcount'];
$error = $error[$element];
echo '<table border="0" cellpadding="3">
<tr bgcolor=#CCCCCC>
<th>Error Code</th>
<th><a href="' . $link1 . '">Case Number</a></th>
<th><a href="' . $link2 . '">Customer</a></th>
<th><a href="' . $link3 . '">Date</a></th>
</tr>';
foreach ($error[1] as $e) {
if ($i%2 == 0) {
$bg = "#EEEEEE";
}
else {
$bg = "#CCCCCC";
}
echo '<tr bgcolor="' . $bg . '"></td>
<td>' . $e["ErrorCodes"] .'</td>';
if($e["Logs"]==""){
echo '<td>' . $e["Case_No"] . '</td>';
}else if($e["Logs"]=="Y"){
echo '<td>' . $e["Case_No"] . '</td>';
}else {
echo '<td><a href=' . $e["Logs"] . ' target=\"_blank\">' . $e["Case_No"] . '</a></td>';
}
echo '<td>' . $e["Customer"] . '</td>
<td>' . $e["Inc_Date"] . '</td>
</tr>';
$i++;
}
echo '<table>';
}
else {
echo '<table border="0" cellpadding="3">
<tr bgcolor=#CCCCCC>
<th># Of Events</th>
<th>Error Code</th>
</tr>';
$i = 0;
foreach ($_SESSION['errcount'] as $C) {
if ($i%2 == 0) {
$bg = "#EEEEEE";
} else {
$bg = "#CCCCCC";
}
echo '
<tr bgcolor="' . $bg . '">
<td>' . $C[0] . '</td>
<td><a href="test.php?page=next&element=' . $i . '">' . $C[1][0]["ErrorCodes"] . '</a></td>
</tr>';
$i++;
}
echo '</table>';
}

?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.