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>";
}
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>";
}
when either Project or No is clicked, they open in a new window with other details under that clicked row, but i want them to open in a child window instead. is there a way to do it?
this is my code
<table id="keywords" class="container">
<thead>
<tr>
<td><span>Project</span></td>
<td><span>No</span></td>
<td><span>Sub ID</span></td>
<td><span>Name</span></td>
<td><span>Requested Amount</span></td>
<td><span>Paid Amount</span></td>
<td><span>Amount To be Paid</span></td>
<td><span>Description</span></td>
<td><span>State</span></td>
</tr>
</thead>
<?php
/* showing table */
$sql = "SELECT * FROM memo ORDER BY No DESC, SubID ASC"
or die("Failed to query database" .mysqli_error());
$result = $link->query($sql);
while ($row = $result->fetch_assoc()) {
print "<tr>";
print "<td >" . $row['Project'] . "</td>";
print "<td >" . $row['No'] . "</td>";
print "<td >" . $row['SubID'] . "</td>";
print "<td >" . $row['Name'] . "</td>";
print "<th >" . $row['RequestAmount'] . "</th>";
print "<th >" . $row['PaidAmount'] . "</th>";
print "<th >" . $row['AmountToPay'] . "</th>";
print "<td >" . $row['Description'] . "</td>";
print "<td >" . $row['State'] . "</td>";
print "</tr>";
}
// print "</table>";
?>
</table>
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>
i have this code for result page:
http://pastebin.com/XK3hdNYY
and this css
http://pastebin.com/rs22p4px
but i have a black block that has nothing to do with css.
For example, when the code is this
echo "<tr>";
echo "<td width='auto' bgcolor=”#FF0000 ″>" . " ". "<b>" . $i . " ". "<b/>". "</td>";
echo "<td width='auto'>" . " " . $row[1] . " " . "</td>";
echo "<td width='auto'>". $row[2] . "</td>";
echo '<td><span class="spoiler-label">'.$row[1].'</span><div class="spoiler-content" style="display: none"><br>'.$row[3].'</div><td>';
echo "</tr>";
i have this table output
when i change the code like this
echo "<tr>";
echo "<td width='auto' bgcolor=”#FF0000 ″>" . " ". "<b>" . $i . " ". "<b/>". "</td>";
echo "<td width='auto'>" . " " . $row[1] . " " . "</td>";
echo "<td width='auto'>". $row[2] . "</td>";
echo "<td width='auto'>". $row[3] . "</td>";
echo '<td><span class="spoiler-label">'.$row[1].'</span><div class="spoiler-content" style="display: none"><br>'.$row[3].'</div><td>';
echo "</tr>";
I have this output:
and when i change like this
echo "<tr>";
echo "<td width='auto' bgcolor=”#FF0000 ″>" . " ". "<b>" . $i . " ". "<b/>". "</td>";
echo "<td width='auto'>" . " " . $row[1] . " " . "</td>";
echo "<td width='auto'>". $row[2] . "</td>";
echo '<td><span class="spoiler-label">'.$row[1].'</span><div class="spoiler-content" style="display: none"><br>'.$row[3].'</div><td>';
echo "<td width='auto'>". $row[3] . "</td>";
echo "</tr>";
my output:
I want remove these black block an and the column too. In the third case, it seems that the column has lost its borders and lines?
Looks like you have an HTML syntax error:
echo '<td><span class="spoiler-label">'.$row[1].'</span><div class="spoiler-content" style="display: none"><br>'.$row[3].'</div><td>';
Should be:
echo '<td><span class="spoiler-label">'.$row[1].'</span><div class="spoiler-content" style="display: none"><br>'.$row[3].'</div></td>';
See the closing </td> at the end of each line. You're opening a new column mistakenly.
A new column without a <th> to represent it will default to a blank column like this.
I have a simple search engine which echo's out results in a table with CSS formatting, this is working fine, however, i would now like to echo a different image after every 10 results.
thankyou to any one who can help me as I have been stuck on this for hours!
this is my echo output code:
echo "<table width='50%' style='border-bottom:1px solid #000000;'";
echo "<tr>";
echo "<td>";
echo "<div id='page-wrap'>";
echo "<div class='discounted-item freeshipping'>";
echo "<a href='./img/users/" . $row['category'] . "/" . $row['username'] . "/" . $row['filename'] . "' rel='lightbox'><img src=\"./img/users/" . $row['category'] . "/" . $row['username'] . "/" . $row['filename'] . "\" alt=\"\" width='20%' height='98%' /></a>";
echo "<div class='reasonbar'><div class='prod-title' style='width: 70%;'>" .$row['fname'] . "</div><div class='reason' style='width: 29%;'><b>". $row['firstname'] . " " . $row['surname'] ."</b></div></div>";
echo "<div class='reasonbar'><div class='prod-title1' style='width: 70%;'>" . $row['lname'] . "</div><div class='reason1' style='width: 29%;'>Category: ". $row['category'] . "</div></div>";
echo "<div class='reasonbar'><div class='prod-title2' style='width: 70%;'>Contact:" . $row['contact'] . "</div><div class='reason2' style='width: 29%;'>Price: £". $row['price'] . "</div></div>";
echo "</td>";
echo "</tr>";
echo "</td>";
echo "</tr>";
echo "</table>";
}
}
else
echo "No results found for \"<b>$search</b>\"";
You can use modolus operator to determine that...
if ( ! ($i % 10)) {
// Alternate.
}
If you don't have a counter variable at your disposal, just declare one outside of your loop and set it to 0 and increment it for each iteration.