Good Day, I want to display the value in my DB in one row. But what is happening now, it is being displayed horizontally
Image Sample
<table class="table table-bordered">
<thead style="font-size:20px;text-align:center;"class="thead-dark">
<tr>
<th class="tblHeader">MODEL</th>
<th class="tblHeader">PERIOD 1</th>
<th class="tblHeader">PERIOD 2</th>
<th class="tblHeader">PERIOD 3</th>
<th class="tblHeader">PERIOD 4</th>
<th class="tblHeader">PERIOD 5</th>
<th class="tblHeader">PERIOD 6</th>
<th class="tblHeader">PERIOD 7</th>
<th class="tblHeader">PERIOD 8</th>
<th class="tblHeader">PERIOD 9</th>
<th class="tblHeader">PERIOD 10</th>
<th class="tblHeader">PERIOD 11</th>
<th class="tblHeader">PERIOD 12</th>
</tr>
</thead>
<?php
$connect = mysqli_connect("localhost", "root", "", "hh_bpm");
$query = "SELECT *
FROM bpm_periods_instance
WHERE Category_Name=1
";
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($result))
{ ?>
<tbody style="font-size:20px; text-align:center;">
<tr>
<td><?php echo $row["Text_Value"];?></td>
</tr>
<?php } mysqli_close($connect);?>
</tbody>
</table>
I want to display the string value in line with Period 1 - 12`
I'm still trying to learn.
First of all, move your while loop just before the <tr>, for you want to have just one table body. Then it's better to have the same number of <th>s and <td>s. I see you have 12 <th>s, so make 12 <td>s in each <tr> (leave them empty if you want, but include them)
The tags is a row containing headings for your table. For your to Match your column names you must have equal number of as th in your table.
<tr>
<th>heading1</th>
<th>heading2</th>
<th>heading3</th>
</tr>
You can now iterate this for your rows.
<tr>
<td>data1</td>
<td>data2</td>
<td>data3</td>
</tr>
You are showing just a singe TD for each row.
What you are missing is a row loop:
while($row = mysqli_fetch_array($result))
{ ?>
<tbody style="font-size:20px; text-align:center;">
<tr>
<?php
foreach($row as $k=>$v)
echo "<td>$v</td>";
?>
</tr>
<?php } mysqli_close($connect);?>
</tbody>
</table>
Alternatively, you should output TDs for all columns manually:
<tr>
<td><?php echo $row["Column1"];?></td>
<td><?php echo $row["Column2"];?></td>
<td><?php echo $row["Column3"];?></td>
<td><?php echo $row["Column4"];?></td>
<td><?php echo $row["Column5"];?></td>
<td><?php echo $row["Column6"];?></td>
...
</tr>
You need a crosstab query to achieve the results that you want. Since there is very little information I'll just give and outline
SELECT info,
sum( if(MONTH(dt)=1,1,0) as Period_1,
sum( if(MONTH(dt)=2,1,0) as Period_2,
//--- repeat for all 12 months
Your query will return 13 columns (info and Period_1 to Period_12). You'll need to adjust the html to cater for this output.
Related
I have problem for show array data from Oracle Database to table HTML.
This is the query :
$sql ="SELECT A.AC,A.CREATED_BY,A.SCHEDULE_COMPLETION_DATE FROM WO A, SECURITY_HEADER B WHERE A.AC LIKE 'PK%' AND A.CREATED_BY=B.\"USER\" AND B.ADOPT_USER_PROFILE LIKE 'MAINT%' AND A.STATUS!='CLOSED' AND A.SCHEDULE_COMPLETION_DATE BETWEEN '$tgl_awal' AND '$tgl_akhir' AND (A.SCHEDULE_COMPLETION_DATE-SYSDATE)<0 ";
$sql_statement = OCIParse($connect,$sql);
OCIExecute($sql_statement);
This is table code
<thead>
<tr bgcolor="#CCCCCC">
<th class="text-center">AC</th>
<th class="text-center">CREATED BY</th>
<th class="text-center">USER PROFILE</th>
<th class="text-center">SCHEDULE COMPLETION DATE</th>
</tr>
</thead>
<?php
while ($row = oci_fetch_array($sql_statement,OCI_BOTH)){
//$no++;
?>
<tbody>
<tr>
<th class="text-center"><font size="2"><?php echo $row['AC']; ?></font></th>
<th class="text-center"><font size="2"><?php echo $row['CREATED_BY']; ?></font></th>
<th class="text-center"><font size="2"><?php echo $row['ADOPT_USER_PROFILE']; ?></font></th>
<th><font size="2"><?php echo $row['SCHEDULE_COMPLETION_DATE']; ?></font></th>
</tr>
</tbody>
<?php
}
oci_free_statement($sql_statement);
oci_close($connect);
?>
</table>
This is a notice :
oci_fetch_array() [function.oci-fetch-array]: ORA-01002: fetch out of sequence in C:\xampp\htdocs\graph\pages\work_orderf3.php on line 544
Line 544
while ($row = oci_fetch_array($sql_statement,OCI_BOTH)){
I created a table and used collapsed visibility to try to hide many columns from being shown. The columns still show, just they show up blank. I want it to show as though those columns don't exist. The reason the are there is there is a search box that searches through the table data. I want it to search those items but not display them.
<table id='example1' class='table table-bordered table-striped'>
<thead>
<tr>
<th>Ticket #</th>
<th>Date</th>
<th>Subject</th>
<th>Status</th>
<th>Close Date</th>
<th>Assigned To</th>
<th>Work Order</th>
<th style='visibility:collapse;'>TID #</th>
<th style='visibility:collapse;'>Modem #</th>
<th style='visibility:collapse;'>MHL #</th>
<th style='visibility:collapse;'>Waybill #</th>
<th style='visibility:collapse;'>TID #</th>
<th style='visibility:collapse;'>ATM Brand</th>
<th style='visibility:collapse;'>ATM Model</th>
<th style='visibility:collapse;'>EPP Serial</th>
<th style='visibility:collapse;'>Router #</th>
</tr>
</thead>
<tbody>"; // output data of each row
while($row = $result->fetch_assoc()) { $href='"#"'; echo "
<tr>
<td><a href='tickets.php?id=".$row[' id ']."'>".$row['id']."</a>
</td>
<td>".$row['timecreated']."</td>
<td>".$row['subject']."</td>
<td>".$row['status']."</td>
<td>".$row['closedate']."</td>
<td>".$row['assignedtoname']."</td>
<td>".$row['workorder']."</td>
<td style='visibility:collapse;'></td>
<td style='visibility:collapse;'></td>
<td style='visibility:collapse;'></td>
<td style='visibility:collapse;'></td>
<td style='visibility:collapse;'></td>
<td style='visibility:collapse;'></td>
<td style='visibility:collapse;'></td>
<td style='visibility:collapse;'></td>
<td style='visibility:collapse;'></td>
</tr>"; } } else { echo "0 results"; } echo "</tbody>
<tfoot>
<tr>
<th>Ticket #</th>
<th>Date</th>
<th>Subject</th>
<th>Status</th>
<th>Close Date</th>
<th>Assigned To</th>
<th>Work Order</th>
<th style='visibility:collapse;'>TID #</th>
<th style='visibility:collapse;'>Modem #</th>
<th style='visibility:collapse;'>MHL #</th>
<th style='visibility:collapse;'>Waybill #</th>
<th style='visibility:collapse;'>TID #</th>
<th style='visibility:collapse;'>ATM Brand</th>
<th style='visibility:collapse;'>ATM Model</th>
<th style='visibility:collapse;'>EPP Serial</th>
<th style='visibility:collapse;'>Router #</th>
</tr>
</tfoot>
</table>
Change "visibility:collapse;" to "display: none;"
As per https://developer.mozilla.org/en-US/docs/Web/CSS/visibility, it seems as if you'll have to use display none, instead.
collapse For table rows, columns, column groups, and row groups the
row(s) or column(s) are hidden and the space they would have occupied
is removed (as if display: none were applied to the column/row of the
table). However, the size of other rows and columns is still
calculated as though the cells in the collapsed row(s) or column(s)
are present. This was designed for fast removal of a row/column from a
table without having to recalculate widths and heights for every
portion of the table. For XUL elements, the computed size of the
element is always zero, regardless of other styles that would normally
affect the size, although margins still take effect. For other
elements, collapse is treated the same as hidden.
I am trying to setup a table column width to only 200px or 10%. However, when I populate the data from the database, the column seems to ignore the column width and expand it as much as it can. Here is my table html.
<table>
<thead>
<tr>
<th><a href='#'>City</a></th>
<th width='200' class='table_width'><a href='#'>name</a></th>
<th><a href='#'>Agent</a></th>
<th>...
//I have tried class and width attribute. both don't work.
</tr>
</thead>
<tbody>
<tr>
//these column data were popluated from database
<td><?= $row->city; ?></td>
<td width='200' class='table_width'><?= $row->_name; ?></td>
//ignore the width and expand the table cell.
<td><?= $row->agent; ?></td>
<td>...
</tr>
You want to use word-wrap:break-word;.
http://jsfiddle.net/RF4F6/1/
HTML
<table>
<thead>
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
<th>Col 4</th>
<th>Col 5</th>
</tr>
</thead>
<tbody>
<tr>
<td>Normal Width</td>
<td>Normal Width</td>
<td class="forcedWidth">hiThisIsAreallyLongStringThatWillHaveToWrapAt200PixelsOrI'llBeUnhappyAndYouWon'tLikeMeWhenI'mUnhappy.</td>
<td>Normal Width</td>
<td>NormalWidth</td>
</tr>
</tbody>
</table>
CSS
table td{
padding:.5em; /* Not essential for this answer, just a little buffer for the jsfiddle */
}
.forcedWidth{
width:200px;
word-wrap:break-word;
display:inline-block;
}
This is the standard behaviour of a table cell.
One way to do this is place a div inside your cells with style="width: 200px; overflow-hidden;"
Using table-layout: fixed for table will force browser to maintain specified dimensions.
I have a spinner and what happens is that whatever number is in the spinner, when the form is submitted, it should display the word "quest" as many times as the number in the spinner.. E.g if number in spinner is 3, then it will display "quest" 3 times in the table.
The problem is displaying it in the table.
At the moment with my current code it is displaying it like this:
quest
quest
quest
Question Id, Option Type, Duration .... These are table headings
It is displaying the words quest outside the table
Instead I want the word "quest" to be displayed in the Question Id column like this:
Question Id, Option Type, Duration...
quest
quest
quest
How can I get it to display it like the example above?
Below is code
<table border=1 id="qandatbl" align="center">
<tr>
<th class="col1">Question No</th>
<th class="col2">Option Type</th>
<th class="col1">Duration</th>
<th class="col2">Weight(%)</th>
<th class="col1">Answer</th>
<th class="col2">Video</th>
<th class="col1">Audio</th>
<th class="col2">Image</th>
</tr>
<?php
$spinnerCount = $_POST['txtQuestion'];
if($spinnerCount > 0) {
for($i = 1; $i <= $spinnerCount; $i++) {
echo "<tr>quest";
}
}
?>
<td class='qid'></td>
<td class="options"></td>
<td class="duration"></td>
<td class="weight"></td>
<td class="answer"></td>
<td class="video"></td>
<td class="audio"></td>
<td class="image"></td>
</tr>
</table>
I did try echo "<td class='qid'></td>"; but this completely failed as well
Try this:
<table border=1 id="qandatbl" align="center">
<tr>
<th class="col1">Question No</th>
<th class="col2">Option Type</th>
<th class="col1">Duration</th>
<th class="col2">Weight(%)</th>
<th class="col1">Answer</th>
<th class="col2">Video</th>
<th class="col1">Audio</th>
<th class="col2">Image</th>
</tr>
<?php
$spinnerCount = $_POST['txtQuestion'];
if($spinnerCount > 0) {
for($i = 1; $i <= $spinnerCount; $i++) {
?>
<tr>
<td class='qid'><?php echo $quest; ?></td>
<td class="options"></td>
<td class="duration"></td>
<td class="weight"></td>
<td class="answer"></td>
<td class="video"></td>
<td class="audio"></td>
<td class="image"></td>
</tr>
<?php
} // For
} // If
?>
</table>
Is this what you want to do? Display "quest" in the first column?
<table border=1 id="qandatbl" align="center">
<tr>
<th class="col1">Question No</th>
<th class="col2">Option Type</th>
<th class="col1">Duration</th>
<th class="col2">Weight(%)</th>
<th class="col1">Answer</th>
<th class="col2">Video</th>
<th class="col1">Audio</th>
<th class="col2">Image</th>
</tr>
<?php
$spinnerCount = $_POST['txtQuestion'];
if($spinnerCount > 0) {
for($i = 1; $i <= $spinnerCount; $i++) { ?>
<tr>
<td class='qid'>quest</td>
<td class="options"></td>
<td class="duration"></td>
<td class="weight"></td>
<td class="answer"></td>
<td class="video"></td>
<td class="audio"></td>
<td class="image"></td>
</tr>
<?php
}
}
?></table>
?>
I have the following code:
<table id="box-table-a" class="tablesorter">
<thead>
<tr>
<th scope="col">B-House/Dorm Name</th>
<th scope="col">Address</th>
<th scope="col">Price Range</th>
<th scope="col">Date Added</th>
<th scope="col">Status</th>
</tr>
</thead>
<?php
$q=mysql_query("select * from property");
while( $f=mysql_fetch_array($q, MYSQL_ASSOC))
{ $p_id=$f["p_id"];
echo"
<tbody>
<tr>
<td onblurr='hover2()' onmouseover='hover(".$p_id.")' onclick='showUser(".$p_id.")'>
<span style='cursor:pointer'>".$f['p_name']."</span></td>
<td id='pretty'>".$f['address']."</td>
<td>".$f['p_name']."</td> <td>".$f['payment_type']."</td> <td>".$status."</td> </tr>
</tbody>
";
}
?>
</table>
Any idea what may be wrong here?
Don't add <tbody></tbody> to every loop in the while! Tablesorter is very sensitive.
You did'nt sort your DB :
$q=mysql_query("select * from property ORDER BY p_name");