I have included some javascript above the setup of my table that I thought would allow me to choose the number of rows but I can't seem to figure out why it doesn't work. The scroll function works but that is the only responsive part of the table.
<script type="text/javascript">
$(document).ready(function() {
$('#example').DataTable( {
responsive: true,
"pageLength": 10
} );
} );
</script>
<div style="height:700px; overflow-y: scroll;">
<table id = "example">
<tr>
<th align="center"> ID</th>
<th>Item Name</th>
<th>Suggested Quantity</th>
<th>Order Quantity</th>
</tr>
<?php
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row['item_id'] ."</td>";
echo "<td>" . $row['ITEM_NAME'] . "</td>";
echo "<td>" . $row['suggested_qty'] . "</td>";
echo "<td>" . $row['suggested_qty'] . "</td>";
echo "</tr>";
}
?>
</table>
</div>
I have a table which is looks like this.
What I want to do is, I want to Highlight (Yellow COLOR) which row has USAGE PER 1K Higher than the AVERAGE. The result should looks like this.
Here is my code to make a row been hightlight when exceed value of average, but I cannot change the value if($row['duh']>'0.77') to the if($row['duh']>'$avg') because it will hightlight all the rows.
$no = 1;
while ($row = mysqli_fetch_array($result))
{
$month1=strtotime($row['month']);
$month=date('m-Y',$month1);
$store_name=$row['store_name'];
$netamt1=$row['netamt'];
$netamt11=number_format($netamt1,2);
$usage1=$row['monusage'];
$usage11=number_format($usage1,2);
$answer=$usage1/$netamt1*1000;
$answer1=number_format($answer,2);
$total+=$answer1;
$avg=$total/$no;
$duh = number_format($row['duh'],2);
echo "<tr>";
echo "<td>".$no."</td>";
echo "<td>".$store_name."</td>";
echo "<td>".$date2111."</td>";
echo "<td>".$netamt11."</td>";
echo "<td>".$usage11."</td>";
if($row['duh']>'0.77') {// 0.77 i cannot change to $avg, because it will hightlight all the rows become yellow
echo "<td style='background-color: #FFFF00;'>".$duh."</td>";}
else {
echo "<td>".$duh."</td>";
}
echo "</tr>";
$no++;
}?>
</tbody>
<tfoot>
<tr>
<th colspan="5">TOTAL</th>
<th><?=($total)?></th>
</tr>
<tr>
<th colspan="5">AVERAGE</th>
<th><?=number_format($avg,4)?></th>
</tr>
</tfoot>
You can add avegage as another column in query result and compare the values against it, e.g.:
SELECT no, outlet, date, sales, usage, usage_per_1k, AVG(usage_per_1k) AS avg
FROM table
WHERE condition;
AND then, add the following to highlight:
if($row['duh']>$row['avg']) {
hightlight all the rows become yellow
echo "<td style='background-color: #FFFF00;'>".$duh."</td>";
}
After keep trying, now i figure out how to hightlight a row depending on the condition average, if Higher than average, the row will Yellow, but I make it RED now. If Lower than average, the color will not change. Im using script in <body> tag, and add class in <tr> tag, then do function.
$no = 1;
while ($row = mysqli_fetch_array($result))
{
$month1=strtotime($row['month']);
$month=date('m-Y',$month1);
$store_name=$row['store_name'];
$netamt1=$row['netamt'];
$netamt11=number_format($netamt1,2);
$usage1=$row['monusage'];
$usage11=number_format($usage1,2);
$answer=$usage1/$netamt1*1000;
$answer1=number_format($answer,2);
$duh = number_format($row['duh'],2);
$total+=$duh;
$avg=$total/$no;
echo "<tr class='y_n';>";
echo "<td>".$no."</td>";
echo "<td>".$store_name."</td>";
echo "<td>".$date2111."</td>";
echo "<td>".$netamt11."</td>";
echo "<td>".$usage11."</td>";
$no++;
echo "<td>".$duh."</td>";
echo "</tr>";
} ?>
<script type="text/javascript">
$('#table_id tr.y_n td').each(function() {
if ($(this).text() >=<?=number_format($avg,2)?>) {
$(this).parent().css('background-color', '#fc9c9c');
}
else
$(this).parent().css('background-color', '#e5f5ff');
});
</script>
</tbody>
<tfoot>
<tr>
<th colspan="5">TOTAL</th>
<th><?=($total)?></th>
</tr>
<tr>
<th colspan="5">AVERAGE</th>
<th><?=number_format($avg,4)?></th></tr>
<tr>
<th colspan="6"><center><?php echo $actionstatus?></center></th>
</tr>
</tfoot>
</table>
Here is the Result :
This is my code the table appears up with the header and everything but the row with the td tag data shows nothing at all
echo "<p></p>";
//display name of the page and some random text
echo "<h2>".$pagename."</h2>";
if($_POST['h_prodid'] > 0){
$newprodid = $_POST['h_prodid'];
$reququantity =$_POST['quantity'];
$_SESSION['basket'][$newprodid]=$reququantity;
echo "<p>Your basket has been updated</p>";
} else {
echo "<p>Existing basket</p>";
}
echo "<table border = '1'>
<tr><th>Product Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Subtotal</th>
</tr>";
echo "<td>".$reququantity."</td>";
echo "</table>";
The reason your data is NOT displaying in the html is because it is NOT in a tr ( table row ) - simply a floating table cell
if( $_SERVER['REQUEST_METHOD']=='POST' ){
echo "<h2>".$pagename."</h2>";
if( isset( $_POST['h_prodid'],$_POST['quantity'] ) ){
if( $_POST['h_prodid'] > 0 ){
$newprodid = $_POST['h_prodid'];
$reququantity =$_POST['quantity'];
$_SESSION['basket'][$newprodid]=$reququantity;
echo "<p>Your basket has been updated</p>";
}else{
echo "<p>Existing basket</p>";
}
echo "
<table border = '1'>
<tr>
<th>Product Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Subtotal</th>
</tr>
<tr>
<td> </td>
<td> </td>
<td>{$reququantity}</td>
<td> </td>
</tr>
</table>";
}
}
I have a problem regarding the width in a bootstrap table, it goes way to the side of the website, screenshot under
http://i.stack.imgur.com/FLZwD.png
EDIT:
<div class="container">
<h1>URL Stats <small>Shortened URL's with their full stats.</small></h1>
<table class="table table-striped table-bordered" id="statstable">
<thead>
<tr>
<th>URL ID</th><th>URL Unique ID</th><th>Short Link</th><th>Redirect Link</th><th>Date Created</th><th>End Date</th><th>Days Left</th>
</tr>
</thead>
<hr>
<tbody>
<?php
$result = mysql_query("SELECT * FROM links WHERE shortlinkid='$shortlinkid'") or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$now = date("Y-m-d");
$start = $row['date_created'];
$end = $row['end_date'];
$diff = (strtotime($end) - strtotime($now))/24/3600;
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['shortlinkid']."</td>";
echo "<td><a href='http://".$row['fullurl']."'>".$row['fullurl']."</a></td>";
echo "<td><a href='".$row['redirect']."'>".$row['redirect']."</a></td>";
echo "<td>".$row['date_created']."</td>";
echo "<td>".$row['end_date']."</td>";
echo "<td>".$diff."</td>";
echo "</tr>";
}
?>
</tbody>
</table>
</div>
This has not been an issue before, and it works fine in other browsers other than Chrome
Change this:
echo "<td><a href='http://".$row['fullurl']."'>".$row['fullurl']."</a></td>";
echo "<td><a href='".$row['redirect']."'>".$row['redirect']."</a></td>";
To this:
echo "<td><a href='http://".$row['fullurl']."'>Full URL</a></td>";
echo "<td><a href='".$row['redirect']."'>Redirect</a></td>";
Instead of echoing the entire URL for the link label, use some descriptive text to click on. Change labels as needed.
I have created a php file called search.php. I want to show the result on a table
I want a table structure like this.
__________________________
| |________________|
| |________________|
| |________________|
|________|________________|
|________________|
|________________|
On the left side I want to place a picture which will be obtained from database and to the right I will place information about the student photo.
Could you write a code. Can we separate photo and the information column by a vertical line only.(if yes,HOW ?? )
<table>
<tr>
<td rowspan="4" style="border-right: 1px solid black">
<img src"whatever.png" alt="" />img
</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
<tr>
<td>3</td>
</tr>
<tr>
<td>4</td>
</tr>
<tr>
<td rowspan="2">
</td>
<td>5</td>
</tr>
<tr>
<td>6</td>
</tr>
</table>
but really: learn html an get used to the boxed model, that is: use divs
<?php
$sql = "Select FROM * `yourtablename` where `id` = 'theidofthestudent'";
if(!mysql_query($sql)){
die(mysql_error());
} else {
echo "<table border="1px" style="text-align:center;" align="justify">";
echo "<th>Photo of student</th>";
echo "<th>Name of the student</th>";
echo "<th>Student Detials</th>";
while($row = mysql_fetch_array($sql)){
echo "<tr>";
echo "<td style="float:left;">' . $row['student_pic'] . "</td>";
echo '<td style="float:right;">' . $row['student_name'] . "</td>";
echo '<td style="float:right;">' . $row['student_details'] . "</td>";
echo "</tr>"
} echo "</table>";
}
?>