I am trying to design an HTML table where the header will stay fixed at the top of the page while scrolling down, but it is not working. Below is my html code....
<table align="center">
<?php
$select = "SELECT * FROM register where r_bid='".$_SESSION["id"]."' order by `name` ";
$result = mysql_query($select) or die(mysql_error());
$res = mysql_query("select * from regi_balic where b_id='".$_SESSION["id"]."'");
$row1=mysql_fetch_array($res);
$i=1;
echo'<thead><tr align="center">
<th width=3%><font size=3><strong>No.</strong></font></th>
<th width=10%><font size=3><strong>IC</strong></font></th>
<th width=12%><font size=3><strong>Name</strong></font></th>
<th width=12%><font size=3><strong>Reference</strong></font></th>
<th width=2%><font size=3><strong>Age</strong></font></th>
<th width=12%><font size=3><strong>Occupatin</strong></font></th>
<th width=5%><font size=3><strong>Mobile No</strong></font></th>
<th width=2%><font size=3><strong>Delete</strong></font></th>
</tr></thead>';
while($row = mysql_fetch_array($result))
{
echo '<tbody><tr>
<td width="3%" align="center" ><font size=3>'.$i.'</font></td>
<td width="10%"><font size=3>'.$row1['name'].'</font></td>
<td width="12%" align="left" ><font size=3>
<a href="edit_detail.phpid='.$row["r_id"].'
&cand_id='.$_SESSION["id"].'&email='.$row["email"].'">'.$row['name'].'</a></font></td>
<td width="12%" align="center" ><font size=3>'.$row['reference'].'</font></td>
<td width="2%" align="right" style="padding-right:8px" >
<fontsize=3>'.$row['age'].'</font></td>
<td width="12%" align="right" style="padding-right:8px"><font
size=3>'.$row['occupation'].'</font></td>
<td width="5%" align="right"><font size=3>'.$row['mob_no'].'</font></td>
<td width="2%"><a href="process_del_client.php?id='.$row['r_id'].'" onClick="return
ConfirmSubmit(\'Are You sure ?\')"><img src = "images/delete.png"></a></td>
</tr></tbody>';
$i++;
}
echo '</table></div></center>';
?>
</div>
and this is my CSS:
.list {
height: 409px;
width: 80%;
overflow: scroll;
}
Something like this? http://jsbin.com/fekoyi/1/edit
table {
height: 1000px; /* To force existence of a scrollbar. */
background: yellow; /* To aid seeing boundaries. */
}
th {
position: fixed; /* Fixes its position to the window. */
top: 0; /* Sets that fixed position to stick to the top of the window. */
width: 100%; /* Fills the width of the window; made it easier to see in your markup. */
background: pink; /* To aid seeing boundaries. */
}
Related
I've got this query to work in the editor but now that I transfer the Code into the table code I can't seem to get it to work...
Is there something I'm doing wrong in order for this to work in the php?
Having never used the SET in a mysql query before I assume it has something to do with this, I've tried moving the SET part to separate it to no avail but not sure whether it's just something really simple that I'm missing?
<table data-role="table" id="table-column" data-theme="f" data-mode="table" class="ui-responsive table-stroke table-stripe">
<thead>
<tr>
<th style="text-align: center" data-priority="persist">Date Recorded</th>
<th style="text-align: center" data-priority="1">Max Temp C°</th>
<th style="text-align: center" data-priority="1">rH%</th>
<th style="text-align: center" data-priority="2">Hours</th>
<th style="text-align: center" data-priority="2">Hours Running Total</th>
<th style="text-align: center" data-priority="persist">pH</th>
</tr>
</thead>
<tbody>
<tr>
<?php
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($link, "SET #runtot:= 0;
SELECT q1.dated, max_temp, max_rh, q1.c, (#runtot := #runtot + q1.c) AS rt
FROM
(SELECT datestamp AS dated,
max_temp,
max_rh,
sum(hours) AS c,
ph
FROM hours
WHERE hours > 0 AND username = '$_SESSION[USERNAME]' AND batch_no = '$_SESSION[batch_no]'
GROUP BY dated
ORDER BY dated) AS q1");
if (!$result) {
die("Query to show fields from table failed");
}
$fields_num = mysqli_num_fields($result);
for($i=0; $i<$fields_num; $i++)
{
$field = mysqli_fetch_field($result);
}
while($row = mysqli_fetch_row($result))
{
?>
<td style="text-align: center; vertical-align: middle"><?php echo "$row[0]"?></td>
<td style="text-align: center; vertical-align: middle"><?php echo "$row[1]"?></td>
<td style="text-align: center; vertical-align: middle"><?php echo "$row[2]"?></td>
<td style="text-align: center; vertical-align: middle"><?php echo "$row[3]"?></td>
<td style="text-align: center; vertical-align: middle"><?php echo "$row[4]"?></td>
<td style="text-align: center; vertical-align: middle"><?php echo "$row[5]"?></td>
</tr>
<?php
}
mysqli_free_result($result)
?>
</tbody>
</table>
Simply changing the mysql query worked wonders.
Removing the SET.... as the first line of the code and then as the last line of the mysql, the following:
ORDER BY d) AS q1, (SELECT #runtot:=0) AS n")
I'm trying to make a scrollable table with fix header. This works well if the data is entered to HTML, but when I try to echo content of my database to the table, the scroll bar messes up and my header is no longer fixed. As seen in the photo, the scroll bar is on each table entry. I've tried .div wrapping up the table body as some did but it doesn't work.
body{
background: lightblue;
}
#tble th {
text-align: left;
background-color: green;
color: white;
}
table{
display: block;
border: 1px solid;
margin-top: 10px;
width: 350px;
}
tbody{
display: block;
height: 50px;
overflow-y: scroll;
}
th {
width: 75px;
}
td {
width: 75px;
}
<html lang="en">
<body>
<table align="center" id="tble">
<thead>
<th style="text-align: center">ID</th>
<th style="text-align: center">Username</th>
<th style="text-align: center">Rights</th>
<th style="text-align: center">Age</th>
</thead>
<tbody>
<tr>
<?php
$conn = mysqli_connect("localhost", "root", "", "account");
$result = mysqli_query($conn, "SELECT * FROM account.log WHERE rights IN ('Admin','User')", MYSQLI_USE_RESULT) or die(mysql_error());
while($row = mysqli_fetch_array( $result )) {
?>
<td style="text-align: center"><?php echo $row['id']; ?></td>
<td style="text-align: center"><?php echo $row['user']; ?></td>
<td style="text-align: center"><?php echo $row['rights']; ?></td>
<td style="text-align: center"><?php echo $row['age']; ?></td>
</tr>
</tbody>
<?php
}
?>
</body>
</table>
Is there something I missed? Hoping someone could point me to the right direction.
<!-- language: lang-html -->
<html lang="en">
<body>
<table align="center" id="tble">
<thead>
<th style="text-align: center">ID</th>
<th style="text-align: center">Username</th>
<th style="text-align: center">Rights</th>
<th style="text-align: center">Age</th>
</thead>
<tbody>
<tr>//move this from here
<?php
$conn = mysqli_connect("localhost", "root", "", "account");
$result = mysqli_query($conn, "SELECT * FROM account.log WHERE rights IN ('Admin','User')", MYSQLI_USE_RESULT) or die(mysql_error());
while($row = mysqli_fetch_array( $result )) {
?>
<tr> //to here
<td style="text-align: center"><?php echo $row['id']; ?></td>
<td style="text-align: center"><?php echo $row['user']; ?></td>
<td style="text-align: center"><?php echo $row['rights']; ?></td>
<td style="text-align: center"><?php echo $row['age']; ?></td>
</tr>
</tbody>
<?php
}
?>
</body>
</table>
I created a table with fix table head. I use this simple CSS to do that.
.table-fixed thead {
width: 97%;
}
.table-fixed tbody {
width: 97%;
height: 340px;
display:block;
overflow:auto;
}
but the n the output will come like this;
I call the table from ajax. so here is the table code;
echo "<table class=\"table table-bordered table-fixed\">
<thead>
<tr>
<th class=\"col-xs-1\">No</th>
<th class=\"col-xs-2\">Name of Student</th>
<th class=\"col-xs-1\">Nic No</th>
<th class=\"col-xs-1\">Reg. No.</th>
<th class=\"col-xs-1\">adm. date</th>
<th class=\"col-xs-1\">room No</th>
<th class=\"col-xs-3\">Address</th>
<th class=\"col-xs-2\">Contact No.</th>
</tr>
</thead>
<tbody>";
$count = 1;
while($row = $result->fetch_assoc()) {
echo"
<tr id=\"".$row["reg_no"]."\" onclick=\"Redirect(this.id)\">
<td class=\"col-xs-1\">".$count."</td>
<td class=\"col-xs-2\">".$row["name_initial"]."</td>
<td class=\"col-xs-1\">".$row["nic"]."</td>
<td class=\"col-xs-1\">".$row["reg_no"]."</td>
<td class=\"col-xs-1\"></td>
<td class=\"col-xs-1\"></td>
<td class=\"col-xs-3\">".$row["resedential_adress"]."</td>
<td class=\"col-xs-2\">".$row["contact_no"]."</td></tr>
";
$count++;
}
echo "
</tbody></table>";
}
please Help me to fix this problem.
Remove display:block; from table-fixed tbody {} It will override default table property
.table-fixed thead {
width: 97%;
}
.table-fixed tbody {
width: 97%;
height: 340px;
overflow:auto;
}
issue is in your css
remove display:block; and try
this code not work in table with mPDF php class
<table>
<tr>
<td class="contentDetails">
<td class="contentDetails">
<h3 style="text-align: right;"><strong>text align right</strong></h3>
<h3 style="text-align: center;"><strong>text align center</strong></h3>
<h3 style="text-align: left;"><strong>text align left</strong></h3>
</td>
</tr>
</table>
i triad use
.contentDetails > h3 {display: block;}
but not work and between td it's html from Editor tinymce
this full code from script
and when do output found content the td text align left not right or center
<?php
$html = '
<h1>mPDF</h1>
<table style="border-collapse: collapse;
font-size: 12px;
font-weight: 700;
margin-top: 5px;
border-top: 1px solid #777;
width: 100%;">
<tbody>
<tr>
<td class="contentDetails">
<h3 style="text-align: right;"><strong>text align right</strong></h3>
<h3 style="text-align: center;"><strong>text align center</strong></h3>
<h3 style="text-align: left;"><strong>text align left</strong></h3>
</td>
</tr>
</tbody>
</table>';
include("mpdf.php");
$mpdf=new mPDF('c');
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
?>
Try the below code. I think it will help you.
<table width="100%">
<tr>
<td class="contentDetails">
<th align="left"> <h3><strong>text align right</strong></h3></th>
<th align="center"> <h3><strong>text align center</strong></h3></th>
<th align="right"> <h3><strong>text align left</strong></h3></th>
</td>
</tr>
</table>
using extra tags in this.
I have prepared a lot of hours a content to print (mPdf v.6). Now i can give an advice to all. Don't use tables to align content or simply hold the content. Almost all css properties of elements work fine. But - but must not be nested in table.
The problem is the width of the container which is fitting with the content. Set table width to 100%
table {
width: 100%;
}
<table>
<tr>
<td class="contentDetails">
<h3 style="text-align: right;"><strong>text align right</strong></h3>
<h3 style="text-align: center;"><strong>text align center</strong></h3>
<h3 style="text-align: left;"><strong>text align left</strong></h3>
</td>
</tr>
</table>
I am creating a table that loops information from my database. I created the table with html and added styling via an external css sheet. The table format is not displaying in any way. None of the borders are displaying and the 100% width is not working. Could my while loop be causing this affect?
<table class="tableproduct">
<tr>
<th class="thproduct">Product ID</th>
<th class="thproduct">Product Name</th>
<th class="thproduct">Price</th>
<th class="thproduct">Category</th>
<th class="thproduct">Description</th>
</tr>
<?php
while($row = mysqli_fetch_assoc($q)) : ?>
<tr>
<td class="tdproduct"><?php echo $row['product_id']; ?> </td>
<td class="tdproduct"><?php echo $row['name']; ?> </td>
<td class="tdproduct"><?php echo $row['price']; ?> </td>
<td class="tdproduct"><?php echo $row['category']; ?> </td>
<td class="tdproduct"><?php echo $row['description']; ?> </td>
</tr>
</table>
<?php endwhile; ?>
.tableproduct {
width: 100%;
border: 1px solid black;
}
.tdproduct {
border: 1px solid black;
}
.thproduct {
height: 100px;
border: 1px solid black;
}
I ended up resolving this.
I had to put an if statement with the while loops and it created the results I was looking for.
I added this to the while loop:
if( $result ){
while($row = mysqli_fetch_assoc($result)) :