I am trying to place my database results into a ScrollBox but im having a difficult time,
I was checking online and it was saying that i need to use the scrollbox:auto function.
But i tried add it too the CSS regarding the table for which the database results go in
but it did not work and just displayed the results all on the page.
Any guidance would be appreciated
CSS
.results
{
bottom: -10px;
position: relative;
top: 90px;
scrollbox: auto;
}
Database Results
echo "<table class='results' border='1'>";
while ($row = mysqli_fetch_array($result))
{
echo "<tr >";
echo "<td>" . '<img style=height:45px; width:45px src="' . $row['Image'] . '"/>' . "</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . "£" . $row['Cost'] . "<br>" . '<a href='.$row['Link'].'>' . '</a>' . "</td>";
echo "</tr>";
}
use overflow: auto; Or overflow:scroll instead of scrollbox: auto;
make sure to give the scrolling-div a fixed height.
Related
I am having this type of problem. I have a table displayed on my webpage. Wherein I have an Action column. I am trying to make my (a href) code open different files depending on what was indicated on my table whether it is pdf or an excel file.
<?php
$con=mysqli_connect("localhost","root","","annualdb");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM aviation_report");
echo "<head><style>
table {
border: 2px solid black;
width: 100%;
height: 100px;
text-align: center;
}
</style></head>";
echo "<table>
<tr>
<th>Agency</th>
<th>FileName</th>
<th>FileType</th>
<th>Date</th>
<th>Action</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['agency'] . "</td>";
echo "<td>" . $row['filename'] . "</td>";
echo "<td>" . $row['filetype'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td><a href='sample.pdf'>OPEN FILE</a></td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
You would have this code:
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['agency'] . "</td>";
echo "<td>" . $row['filename'] . "</td>";
echo "<td>" . $row['filetype'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td><a target='_blank' href='" . $row['filename'] . "'>OPEN FILE</a></td>";
echo "</tr>";
}
I want to align text in center under table but i dnt know how to do this
Here is my code
echo "<td>" . $row['Firstname'] ." ". $row['Lastname'] ."</td>";
echo "<td>" . $row['Marks'] . "</td>";
echo "<td>" . $row['percent'] . "</td>";
echo "<td>" . $row['Status'] . "</td>";
Kindly help me how to do this.
i tried this but not working
echo '<td tyle="text-align:center;">' . $row['enroll'] . '</td>';
i think you did typo there.replace tyle with style
echo '<td style="text-align:center;">' . $row['enroll'] . '</td>';
or you can also try
echo '<td align="center">' . $row['enroll'] . '</td>';
First, include this code to see the table borders <table border="1">
Next, include this before your </header> tag if you got everything in an HTML Doctype:
<style type="text/css">
table td {
text-align: center;
}
</style>
And your done.
In CSS
.Classname td{
text-align: center;
}
In Inline
echo '<td style="text-align:center;">' . $row['enroll'] . '</td>';
Or
echo '<td align="center">' . $row['enroll'] . '</td>';
Use CSS instead:
.tableClass td{
text-align: center;
}
Inline styles are annoying to try and maintain, especially if they're output using PHP.
You can use : align attribute for td :
echo '<td align="center">' . $row['enroll'] . '</td>';
Cheers
Use css or inside code write as:
echo '<td style='.'"'.'text-align:center'.';">' . $row['enroll'] . '</td>';
Your code didn't work because there is a typing error - missing s in style
echo '<td tyle="text-align:center;">' . $row['enroll'] . '</td>';
should be
echo '<td style="text-align:center;">' . $row['enroll'] . '</td>';
php table text align center
echo " < td align='center'>" . $row['enroll'] . "< /td>";
I have a table that gets it´s content from a database, and I want to make the text in the column to the right align-right. I know how to do it when its HTML and the content is in the code, but I can't get it to work when the content is outputted from a database.
Down here you can see my code for the table: (in the collumn "ingredienser", I want to set the text-align to right.
<?php
$con = mysql_connect("****","****","****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("paj", $con);
$result = mysql_query("SELECT * FROM meny");
echo "<div id='menyer'>";
echo "<table border='1'>
<tr>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<div class='mall" . $row['mall'] . "'>";
echo "<tr>";
echo "<td>" . $row['namn'] . "</td>";
echo "<td>" . $row['ingredienser'] . "'</td>";
echo "</tr>";
Just add some CSS above your php code
<style>
table td {
text-align: right;
}
</style>
The above will right align text inside table cells
echo "<td><div align='right'>" . $row['ingredienser'] . "'</div></td>";
if this is the extent of your table, then you can definitely just use the following css:
.mall{
text-align:right;
}
I would suggest putting it in your external css file, but if you don't have one, then put it in a style tag inside of your body or table tag, depending on what kind of scope you want it to have like this:
<style>
.mall{
text-align:right;
}
</style>
set align="right" to your tr
while($row = mysql_fetch_array($result))
{
echo "<div class='mall" . $row['mall'] . "'>";
echo "<tr align='right'>";
echo "<td>" . $row['namn'] . "</td>";
echo "<td>" . $row['ingredienser'] . "'</td>";
echo "</tr>";
Just add styling to that one particular cell, it will apply to the entire column as it loops. As such,
echo "<td style=\"text-align:right;\">" . $row['ingredienser'] . "'</td>";
If you align the Table TD to text-align:right, EVERY single cell will be effected.
Is there any reason that the following code and syle wouldn't work? The only problem is that I can't get the text to change color, it stays black, which would be fine but the background color is black. I know it's there because I can highlight the text with the cursor and it's there in the table. Here's my code fragment.
This is from the index.php page.
while($row=mysqli_fetch_array($result))
{
echo "<tr id= "Data'" class='"Data'">";
echo "<td id= " cell ">" . $row['Name'] . "</td>";
echo "<td id= " cell ">" . $row['Subject'] . "</td>";
echo "<td id= " cell ">" . $row['Date'] . "</td>";
echo "<td id= " cell ">" . $row['Source'] . "</td>";
echo "<td id= " cell ">" . $row['Comment'] . "</td>";
echo "</tr>";
}
here's the css rule that SHOULD be applied.....but isn't.
#Cell{
border-style: solid;
border-color: black;
border-width: 1px;
color: white;
<td id= " cell "> is not equivalent to <td id="cell"> because HTML does not recursively evaluate itself. So the former tag is invalid gobbledegook without an id. You also cannot give the same id to more than one element.
Why your are using " cell "
Here is correct code
while($row=mysqli_fetch_array($result))
{
echo "<tr id=\"Data\" class=\"Data\">";
echo "<td id=\"cell\">" . $row['Name'] . "</td>";
echo "<td id=\"cell\">" . $row['Subject'] . "</td>";
echo "<td id=\"cell\">" . $row['Date'] . "</td>";
echo "<td id=\"cell\">" . $row['Source'] . "</td>";
echo "<td id=\"cell\">" . $row['Comment'] . "</td>";
echo "</tr>";
}
I am having trouble applying CSS styles to my dynamic table. I am connecting to a database and I know the data is populated correctly and displaying. My issue is that there are 900 records and I want to limit the table size, utilizing a scrollbar. I have read elseware that the proper CSS style nodes to accomplish this are: How to specify table's height such that a vertical scroll bar appears?
overflow: auto;
height: 700px;
display: block;
overflow-y: scroll;
At first I attempted this with inline styling (a no-no.. I realize), but it didn't work. I have read about adding a 'class' to the table and/or individual rows, which would then be reflected in my CSS style sheet, but I can't seem to figure out how to accomplish this. I get syntax errors when I add 'span' or 'class' tag designators to the PHP (I imagine from utilizing 'ECHO' - which both require double quotes).
Good example of what I'm trying to accomplish: http://www.timrivera.com/tests/csstables.html#markupIE
The PHP code snippet below has good syntax, but I don't know where to add the class or span designators appropriately. One thing to note - I need to have different styles for different tables, so changing the global 'table' CSS isn't going to work.
//Function that gets the SQL recordset.
$result2 = Get_Package_Info_EXT($conn, $var_PartNumber);
//do the table edits here.
echo "<table border='1' >
<tr>
<th>Facility</th>
<th>Process Flow</th>
<th>Operation</th>
<th>Device</th>
<th>Item</th>
<th>Value</th>
<th>Database Source</th>
</tr>";
while($row2 = oci_fetch_array($result2)){
echo "<tr>";
echo "<td>" . $row2['FACILITY_AT'] . "</td>";
echo "<td>" . $row2['SUB_FLOW_TYPE'] . "</td>";
echo "<td>" . $row2['OPN_NAME'] . "</td>";
echo "<td>" . $row2['SPEC_DEVICE'] . "</td>";
echo "<td>" . $row2['COMPONENT_NAME'] . "</td>";
echo "<td>" . $row2['COMPONENT_VALUE'] . "</td>";
echo "<td>" . $row2['SOURCE'] . "</td>";
echo "</tr>";
}
echo "</table>";
I think the best way would be to wrap a div around the table and give the div a height.
http://phpfiddle.org/main/code/i7h-9b1
<style type="text/css">
#scroll {
height: 100px; /* Max height of table */
overflow-y: scroll;
width: 340px;
}
</style>
<div id="scroll">
table
</div>
Using your code:
echo '
<style type="text/css">
#scroll {
height: 100px; /* Max height of table */
overflow-y: scroll;
width: 340px;
}
</style>';
//Function that gets the SQL recordset.
$result2 = Get_Package_Info_EXT($conn, $var_PartNumber);
//do the table edits here.
echo "<div id='scroll'><table border='1' >
<tr>
<th>Facility</th>
<th>Process Flow</th>
<th>Operation</th>
<th>Device</th>
<th>Item</th>
<th>Value</th>
<th>Database Source</th>
</tr>";
while($row2 = oci_fetch_array($result2)){
echo "<tr>";
echo "<td>" . $row2['FACILITY_AT'] . "</td>";
echo "<td>" . $row2['SUB_FLOW_TYPE'] . "</td>";
echo "<td>" . $row2['OPN_NAME'] . "</td>";
echo "<td>" . $row2['SPEC_DEVICE'] . "</td>";
echo "<td>" . $row2['COMPONENT_NAME'] . "</td>";
echo "<td>" . $row2['COMPONENT_VALUE'] . "</td>";
echo "<td>" . $row2['SOURCE'] . "</td>";
echo "</tr>";
}
echo "</table></div>";
Edit your PHP code to...
//Function that gets the SQL recordset.
$result2 = Get_Package_Info_EXT($conn, $var_PartNumber);
//do the table edits here.
echo "<div class=\"table-container\">";
echo "<table border='1' >
<tr>
<th>Facility</th>
<th>Process Flow</th>
<th>Operation</th>
<th>Device</th>
<th>Item</th>
<th>Value</th>
<th>Database Source</th>
</tr>";
while($row2 = oci_fetch_array($result2)){
echo "<tr>";
echo "<td>" . $row2['FACILITY_AT'] . "</td>";
echo "<td>" . $row2['SUB_FLOW_TYPE'] . "</td>";
echo "<td>" . $row2['OPN_NAME'] . "</td>";
echo "<td>" . $row2['SPEC_DEVICE'] . "</td>";
echo "<td>" . $row2['COMPONENT_NAME'] . "</td>";
echo "<td>" . $row2['COMPONENT_VALUE'] . "</td>";
echo "<td>" . $row2['SOURCE'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "</div>";
Then just style using
div.table-container table {}
Using Calum's style format you could do this:
//Function that gets the SQL recordset.
$result2 = Get_Package_Info_EXT($conn, $var_PartNumber);
//do the table edits here.
echo "<style>#size{height:100px;width:340px;overflow-y:scroll;}</style>";
echo "<table id='size' border='1'>
<tr>
<th>Facility</th>
<th>Process Flow</th>
<th>Operation</th>
<th>Device</th>
<th>Item</th>
<th>Value</th>
<th>Database Source</th>
</tr>";
while($row2 = oci_fetch_array($result2)){
echo "<tr>";
echo "<td>" . $row2['FACILITY_AT'] . "</td>";
echo "<td>" . $row2['SUB_FLOW_TYPE'] . "</td>";
echo "<td>" . $row2['OPN_NAME'] . "</td>";
echo "<td>" . $row2['SPEC_DEVICE'] . "</td>";
echo "<td>" . $row2['COMPONENT_NAME'] . "</td>";
echo "<td>" . $row2['COMPONENT_VALUE'] . "</td>";
echo "<td>" . $row2['SOURCE'] . "</td>";
echo "</tr>";
}
echo "</table>";
I tested it and works fine. And for the different table styles you could:
<style>
#table1
{
style code here
}
#table2
{
style code here
}
</style>
and so on... then you could apply them to the tables:
<table id="table1">
...
</table>
<table id="table2">
...
</table>