I want to make all the rows in the same size, but rows height with data is large. I want to fix this row size for empty rows. Table class name is demo.
Demo
<?php
while($fet=mysql_fetch_assoc($sql1))
{
$id=$fet['c_id'];
$address=$fet['address'];
$chk=$fet["c_name"];
$in=$in+1;
echo "<tr>";
echo "<td style='align:center'><a class='astext' href='client_view.php?cid=".$fet["c_id"]."'>".$fet["c_name"]."</a></td>";
echo "<td style='align:center'><a class='ima' href='client_details.php?cid=".$fet["c_id"]."'><img src='image/edit1.png' alt='edit' style='width:20px; height:20px' title=Edit></a></td><td style='align:center'>
<a class='ima' href='clients.php?del=".$fet["c_id"]."'><img src='image/delete1.png' alt='delete' style='width:20px;height:20px' title=Delete></a></td>";
echo "</tr>";
}
if ($in < 10) {
$empty_rows = 10 - mysql_num_rows($sql1);
for ($m = 0; $m < $empty_rows; $m++) {
echo '<tr><td></td><td></td><td></td></tr>';
}
}
?>
You need to add following CSS in your code.
.demo td{
height:20px;
}
Demo
Add fixed height to tr like
table tr {
height: 40px;
box-sizing: border-box;
}
check fiddle: http://jsfiddle.net/4gqgzdL8/1/
If you need box-sizing you can use it otherwise don't use
Try to set height and line-height for td like this: Demo
.demo td {
line-height:28px;
height:28px;
}
Related
I did the nth child rule in css but it the colors are not alternate. Colors are all the same each rows and columns. My code is a multiplication table with a supposed alternate color. Im having a hard time knowing what I should do to modify or add in my php code to create the desired output (alternate colors in rows and columns in the multiplication table).
Below is my php code:
<?php
for($row=0; $row<=10; $row++){
echo "<tr>";
for($column=0; $column<=10; $column++){
if($row==0 && $column==0){
echo "<td></td>";
}
else{
echo "<td>". $row * $column. "</td>";
}
}
}
echo "</tr>";
?>
CSS code:
table, th, td {
border: 1px solid black;
}
td {
padding: 15px;
}
.bold{
font-weight: bold;
font-size: 1.3em;
}
table tr:nth-child(odd) {
background-color: yellow;
}
table tr:nth-child(even) {
background-color: red;
}
you forget to use the <table> tag and your CSS address it from the table.
<?php
echo "<table>";
for($row=0; $row<=10; $row++){
echo "<tr>";
for($column=0; $column<=10; $column++){
if($row==0 && $column==0){
echo "<td></td>";
}
else{
echo "<td>". $row * $column. "</td>";
}
}
echo "</tr>";
}
echo "</table>";
?>
EDIT: i found out, itsin my other answer below.
I want to present a graph in php and can create the columns, but when i try to increment the percentage to correspond with the css width of the .inner class it wont increment for each element in he array. How can I increment the width for each element in the array?
$percentage = array(0.2,0.4,0.5,0.6,0.7,0.8);
for($i=0;$i<6;$i++){
echo "<div class='outter'>
<div class='inner'>"; echo $percentage[$i]; echo "
</div>
</div>";
echo "<style type='text/css'>";
echo ".outter{height:25px;width:500%;border-right:solid 1px #000;}";
echo ".inner{height:25px;width:";echo $percentage[i]; echo "%;border-right:solid 1px #000;background-color:#02abff;}";
echo "</style>";
}
i can do it in html and css but i want to do it php. Thanks.
Not sure if you have noticed, but the actual values you have there are 0.X%, and this is not exactly a valid width. You might want to multiply that value by 10 (or by 100) to get to 2% (or 20%).
$percentage = array(0.2,0.4,0.5,0.6,0.7,0.8);
foreach ($percentage as $key => $val) {
echo "<div class='outter'>
<div class='inner'>";
echo $val;
echo "</div>
</div>";
echo "<style type='text/css'>";
echo ".outter{height:25px;width:500%;border-right:solid 1px #000;}";
echo ".inner{height:25px;width:";
echo $val * 10;
echo "%;border-right:solid 1px #000;background-color:#02abff;}";
echo "</style>";
}
I also changed the for loop that you had there to foreach loop, which makes more sense when working with arrays.
I found out. I had to put the styling inside the html tag:
foreach($percentage as $percent){
echo "<div class='outter' style='height:25px;width:500%;border-right:solid 1px #000;'>
<div class='inner' style='height:25px;width:"; echo $percent; echo "%;border-right:solid 1px #000;background-color:#02abff;'>"; echo $percent; echo "
</div>
</div>";
}
I have a procedural while loop that echos out rows in my DB like:
echo '<tr align="left"> <td>'.$row['address'].','.$row['state'].'</td>'.
'<td><a href="'.$row['shopurl'].'">'.$row['datedesc'].'</td>'.
'</tr>';
And works great! The problem now is that I need to add a "SOLD OUT" png across the address & state, of only one (currently) of the rows. I have CSS:
#sold-out{
background-image: url("/graphics/png/soldout.png");
}
With the image as the back-ground.
How can I add a Z-Index to php inside a While loop?
Thanks in advance!
You do not add z-index to PHP, you add it to CSS. However, in this case, you can simply print out an absolutely positioned div with the image in the td that you want.
PHP
foreach ($rows as $row) {
echo '<tr align="left">
<td>';
//conditional to determine if row is sold out
if ($row['soldOut'] === 'yes') {
echo '<div class="sold-out"> </div>';
}
echo $row['address'].','.$row['state'].'</td>'.
'<td><a href="'.$row['shopurl'].'">'.$row['datedesc'].'</td>'.
'</tr>';
}
CSS
.sold-out {
position:absolute;
background-image: url("/graphics/png/soldout.png");
opacity: 0.8;
top: 0;
left: 0;
right: 0;
bottom: 0;
I have a generated php table which I would like to apply style in my style sheet, so for example top:15px, left:10px ect..., not sure how call the table and link it with css -
echo "<table border=1>";
for ($i=0;$i<count($calls);$i++){
for ($j=0;$j<count($days);$j++){
$k = $days[$i].$times[$j];
if (array_key_exists($k,$date)){
echo "<td colspan='{$date[$k][1]}'>".
"{$date[$k][0]}</td>";
$j+=$date[$k][1]-1;
}else
echo "<td style='color:gray'>$k</td>";
}
echo "</tr>";
}
echo "</table>";
any help much appreciated, thank you
echo '<table style="top: 15px; left:10px;">';
or
echo '<table class="someClass">';
and then use CSS
.someClass{
top: 15px;
left: 10px;
}
Give the table an id
echo "<table id=\"my_table\" border=1>";
And then use this in the <head> tag of the document:
<style type="text/css">
#my_table {
top: 15px;
...
}
</style>
echo "<table style=\"border: 1px; top:15px; left: 10px;\">";
Is this statement not working?
echo "<table border=1 style=\"top:15px; left:10px\">";
for ($i=0; $i<count($calls); $i++) {
for ($j=0;$j<count($days);$j++) {
$k = $days[$i].$times[$j];
if (array_key_exists($k,$date)) {
echo "<td colspan='{$date[$k][1]}'>".
"{$date[$k][0]}</td>";
$j+=$date[$k][1]-1;
} else {
echo "<td style='color:gray'>$k</td>";
}
}
echo "</tr>";
}
echo "</table>";
I am looking for a solution to use the alternating colors row design in my table which is from a csv.
my code:
<?php
echo "<table style='text-align: left; width: 99%;' border='1'>\n\n
<thead>
<tr>
<th>data</th>
</tr>
</thead>";
$f = fopen("local/datafiles.csv", "r");
while (($line = fgetcsv($f)) !== false) {
echo "<tr class='odds'>";
foreach ($line as $cell) {
echo "<td style='font-weight: bold;'>" . htmlspecialchars($cell) . "</td>";
}
echo "</tr>\n";
}
fclose($f);
echo "\n</table>";
?>
so how can i have the tr class to alternate from odds and even?
thanks
have a variable
int count =0;
increment count on every iteration and take modolous by
count % 2
if(count % 2 == 0)
color = red //(make color of row = red)
else
color = yellow //(make color of row = yello)
count=count+1;
thats just an idea, u can accomodate this in ur code
You could use the css pseudo-selector :nth-of-type(odd|even)
http://reference.sitepoint.com/css/pseudoclass-nthoftype
If the ID of the table is styledTable, your stylesheet would look like:
#styledTable {
text-align: left;
width: 99%;
border: 1px solid black;
}
#styledTable tr:nth-of-type(even) {
background-color: red;
}
#styledTable tr:nth-of-type(odd) {
background-color: blue;
}
<?php
echo "<table style='text-align: left; width: 99%;' border='1'>\n\n
<thead>
<tr>
<th>data</th>
</tr>
</thead>";
$f = fopen("local/datafiles.csv", "r");
$i = 0;
while (($line = fgetcsv($f)) !== false) {
echo "<tr style='background-color: ".(($i%2)?'green':'blue').";'>";
foreach ($line as $cell) {
echo "<td style='font-weight: bold;'>" . htmlspecialchars($cell) . "</td>";
}
echo "</tr>\n";
$i++;
}
fclose($f);
echo "\n</table>";
?>
Or you could assign a class just the same way and style it using css. This is much better practice.
I will give you a better but much simpler solution, through CSS. First of all uniquely identify your table, i will show you a more general option.
table tr { backgroun: #ddd; }
table tr:nth-child(2n) { background: #ccc; }