Hi all,
I am working on a script that displays dynamic rows of questions in a HTML table. Each question can have one of two stats, open (not answered) or closed (answered). If the question is open a form button is display which is clickable and opens another page.
The questions are stored in a data table (ItemCategory), this table can be edited by the user so the number of questions can vary (dynamic).
When the HTML table is loaded is displays row by row the question in ItemCategory and depending on if the question has already been answerd displays the open button or the closed iamge.
[ATTACH]5359[/ATTACH]
Because the question list is dynamic the stored answers data table needs to be queried so I am using the result of a query from the Information Schema to return the column names, and then creates an array of column names, ($SeqIDArray).
$strSQLCol = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME= '".$_SESSION['NX]."_Active' AND COLUMN_NAME LIKE 'SeqID%'";
$rsCol = mysqli_query($link,$strSQLCol);
$SeqList = array();
do {
$SeqList[] = $row;
} while($row = $rsCol->fetch_assoc());
$SeqIDArray = array();
foreach($SeqList as $key => $value) {
if (1 > $key) { continue; }
$SeqIDArray[] = 'SeqID' . $key;
}
The array content looks like:
Array ( [0] => SeqID1 [1] => SeqID2 [2] => SeqID3 [3] => SeqID4 [4] => SeqID5 [5] => SeqID6 [6] => SeqID7 [7] => SeqID8 [8] => SeqID9 [9] => SeqID10 [10] => SeqID11 [11] => SeqID12 [12] => SeqID13 [13] => SeqID14 [14] => SeqID15 [15] => SeqID16 [16] => SeqID17 [17] => SeqID18 [18] => SeqID19 [19] => SeqID20 [20] => SeqID21 [21] => SeqID22 [22] => SeqID23 [23] => SeqID24 [24] => SeqID25 [25] => SeqID26 [26] => SeqID27 [27] => SeqID28 [28] => SeqID29 [29] => SeqID30 [30] => SeqID31 [31] => SeqID32 [32] => SeqID33 [33] => SeqID34 [34] => SeqID35 [35] => SeqID36 [36] => SeqID37 [37] => SeqID38 [38] => SeqID39 [39] => SeqID40 [40] => SeqID41 [41] => SeqID42 [42] => SeqID43 [43] => SeqID44 [44] => SeqID45 [45] => SeqID46 [46] => SeqID47 )
I then use the array to create a query to return the results from the table which holds the answered and un-answered list.
$SQLActive = "SELECT " . join(', ', $SeqIDArray) . " FROM ".$_SESSION['NX']."_Active WHERE UniqueID = '".$_SESSION['UniqueID']."'";
$SeqActive = mysqli_query($link,$SQLActive);
while ($row = mysqli_fetch_assoc($SeqActive)) {
$Seq[] = $row;
}
This result of the query is:
Array ( [0] => Array ( [SeqID1] => 1 [SeqID2] => 1 [SeqID3] => [SeqID4] => [SeqID5] => [SeqID6] => [SeqID7] => [SeqID8] => [SeqID9] => [SeqID10] => [SeqID11] => [SeqID12] => [SeqID13] => [SeqID14] => [SeqID15] => [SeqID16] => [SeqID17] => [SeqID18] => [SeqID19] => [SeqID20] => [SeqID21] => [SeqID22] => [SeqID23] => [SeqID24] => [SeqID25] => [SeqID26] => [SeqID27] => [SeqID28] => [SeqID29] => [SeqID30] => [SeqID31] => [SeqID32] => [SeqID33] => [SeqID34] => [SeqID35] => [SeqID36] => [SeqID37] => [SeqID38] => [SeqID39] => [SeqID40] => [SeqID41] => [SeqID42] => [SeqID43] => [SeqID44] => [SeqID45] => [SeqID46] => [SeqID47] => ) )
As you can see if a question has been answered the column contains a "1", as in [SeqID1] => 1 [SeqID2] => 1.
All of the above works, it may not be the right way to do it but it works.
Now this is where I have an issue. In the body of the page I display the list of questions, row by row.
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<? do { ?>
<? $_SESSION['TableID'] = $row_SeqList['TableID'];?>
<tr>
<td width="71%" class="tablelist"><?php print $row_SeqHead['SeqHeader']; ?></td>
<td width="7%" class="tablelist"><?php print $row_SeqHead['TableID']; ?></td>
<td width="16%" class="openbutton">
<?php
foreach($Seq as $key => $value) {
foreach ($Seq as $val) {
if ($val == 1){ ?>
<img src="images/completebutton.png" width="72" height="29">
<? } else { ?>
<a href="table01.php?TableID=<?php echo $row_SeqHead['TableID']; ?>" target="_self"><img src="images/openbutton.png" width="72" height="29"></a>
<?php }
}
}?>
</td>
</tr>
<?php } while ($row_SeqHead = mysqli_fetch_assoc($SeqHead)); ?>
</table>
The problem I have is if the question has been answered the question row is still displaying the open button and not the closed image.
How can I use the content of array $Seq to display the correct open button or closed image.
Or should I be doing this a completely different way. Your help and comments would be great.
Many thanks in advance for your time.
question_list.png