jeger
jeger

Reputation: 15

Adding extra table row

I'm stuck and can't figure this out.

I have this piece of code which is basically generating a table taking data from SQL cursor. I need to add one extra table row <tr> (which will be filled with additional info) after each row. I've tried putting the new row in several places, but there is never any output data for it. This is someone else's code that I'm trying to modify.

  $top_i=min($pagesize-1,$numrows-$start);
  for($i = 0;$i<=$top_i;$i++) {
  if (($i%2)==1)
    echo "<tr class='saraksts_row0'>";

  else
    echo "<tr class='saraksts_row1'>";


  $res=mssql_query("fetch absolute ".($start+$i)." from saraksts_cursor ");
  $row=mssql_fetch_array($res);

  $itemp = 0;
  foreach($fields as $field) {
        $key = $field[0];
          if($field[2]) {
              eval($field[2] );
          }
          $itemp++;
          $val = ($row[$key] == "") ? "&nbsp;" : $row[$key];

          // Get rid of right and left border, set topmost border
          $st="";
          if ($itemp==1)
            $st.="border-left-style:none;";
          if ($itemp==$numfields)
            $st.="border-right-style:none;";
          if ($i==$top_i)
            $st.="border-bottom-style:solid;";

    echo "<td style='$st'>$val</td>";
  }
  $itemp = 0;

  echo "</tr>\n";
}

Upvotes: 1

Views: 197

Answers (2)

tvanfosson
tvanfosson

Reputation: 532555

The place where you want to add the extra row is after closing the first row and before the iteration moves to the next one. Note, it appears that you are doing some styling based on whether the row is odd or even. If you want this new row to have the same styling, I suggest you store the class you're applying to the preceding row so that you can also apply it to this row.

  echo "</tr>\n";
  echo "<tr><td>...</td><td>...</td></tr>\n"; /* Add the new row here */
}

Upvotes: 1

Eugen Rieck
Eugen Rieck

Reputation: 65294

...
            $st.="border-bottom-style:solid;";

    echo "<td style='$st'>$val</td>";
  }

  //Here we go
  echo '<td style="blah">'.$yourotherinfo.'</td>';


  $itemp = 0;

echo "</tr>\n";

Upvotes: 0

Related Questions