Hello i have a table with some fields like
here i want make colors for table entire rows..means if ASR value is 75 to 100 should get one color and 50 to 75 should get another color and below 50 should get another color.
and here is my php code
<table width="75%" border="1">
<tr>
<td align="center">channel no</td>
<td align="center">IP</td>
<td align="center">Total calls</td>
<td align="center">Connected calls</td>
<td align="center">Disconnected calls</td>
<td align="center">Duration</td>
<td align="center">ASR</td>
<td align="center">ACD</td>
</tr>
<?php
while ($row = mysql_fetch_assoc($result)) {
//$minutes = gmdate("H:i:s", $row['tduration']);
echo "<tr>
<td>".$row['channel']." </td>
<td>".$row['ip']." </td>
<td>".$row['totalcalls']." </td>";
if ($row['totalcalls']>1){
$sql1 = "SELECT count(duration) as count FROM gateways where duration=0 and ip='".$_POST['ip']."' and channel='".$row['channel']. "' and (connect_datetime BETWEEN ' ".$_POST['toval']." ' and '".$_POST['fromval']."' or disconnect_datetime BETWEEN ' ".$_POST['toval']." ' and '".$_POST['fromval']."' ) Group by channel";
$result1 = mysql_query($sql1, $link);
$norow=mysql_fetch_assoc($result1);
$attenedcalls=($row['totalcalls']-$norow['count']);
echo "<td>".$attenedcalls." </td>";
$disconnectedcalls=($row['totalcalls']-$attenedcalls);
echo "<td>".$disconnectedcalls." </td>";
echo " <td>".$row['tduration']." </td>";
echo "<td>".(($attenedcalls/$row['totalcalls'])*100)."</td>";
}else{
echo "<td>".$row['totalcalls']."</td>";
echo "<td>100</td>";
}
$minutes = gmdate("H:i:s", ($row['tduration']/$attenedcalls));
echo " <td>".$minutes." </td>
</tr>";
}
?>
</table>
thanks in advance
You can try like this
<table width="75%" border="1">
<tr>
<td align="center">channel no</td>
<td align="center">IP</td>
<td align="center">Total calls</td>
<td align="center">Connected calls</td>
<td align="center">Disconnected calls</td>
<td align="center">Duration</td>
<td align="center">ASR</td>
<td align="center">ACD</td>
</tr>
<?php
while ($row = mysql_fetch_assoc($result)) {
$color = '';
if ($row['totalcalls']>1){
$sql1 = "SELECT count(duration) as count FROM gateways where duration=0 and ip='".$_POST['ip']."' and channel='".$row['channel']. "' and (connect_datetime BETWEEN ' ".$_POST['toval']." ' and '".$_POST['fromval']."' or disconnect_datetime BETWEEN ' ".$_POST['toval']." ' and '".$_POST['fromval']."' ) Group by channel";
$result1 = mysql_query($sql1, $link);
$norow=mysql_fetch_assoc($result1);
$attenedcalls=($row['totalcalls']-$norow['count']);
$asr = (($attenedcalls/$row['totalcalls'])*100);
if($asr >= 75 && $asr <=100 ){
$color = 'red';
}else if($asr >= 50 && $asr < 75){
$color = 'cyan';
}else if($asr < 50){
$color = 'blue';
}
}
//$minutes = gmdate("H:i:s", $row['tduration']);
echo "<tr style='background-color : ".$color."'>
<td>".$row['channel']." </td>
<td>".$row['ip']." </td>
<td>".$row['totalcalls']." </td>";
if ($row['totalcalls']>1){
echo "<td>".$attenedcalls." </td>";
$disconnectedcalls=($row['totalcalls']-$attenedcalls);
echo "<td>".$disconnectedcalls." </td>";
echo " <td>".$row['tduration']." </td>";
echo "<td>".$asr."</td>";
}else{
echo "<td>".$row['totalcalls']."</td>";
echo "<td>100</td>";
}
$minutes = gmdate("H:i:s", ($row['tduration']/$attenedcalls));
echo " <td>".$minutes." </td>
</tr>";
}
?>
</table>
[...]
while ($row = mysql_fetch_assoc($result)) {
$asrVal=(($attenedcalls/$row['totalcalls'])*100);
if($asrVal>=50 && $asrVal <=75) $class="from50to75";
if($asrVal>=75 && $asrVal <=100) $class="from75to100";
if($asrVal<50) $class="below50";
//$minutes = gmdate("H:i:s", $row['tduration']);
echo "<tr class='$class'>
[...]
then add:
<style>
tr.from50to75 td{background-color:red;}
tr.from75to100 td{background-color:green;}
tr.below50 td{background-color:blue;}
</style>
Modify your while loop so that you compute the ASR value before emitting the <tr> tag. Use that value to select a class according to the classification you have set up, and emit a tag of the form <tr class=foo> where foo is the class name you have selected. Then it’s just a matter of writing CSS rules for the classes, using class selectors like tr.foo.
(Provided that you have not set color on the td cells. If you have, you need to use selectors like tr.foo td to override such settings.)
Related
I just want to get the contents of the dropdown and store it in array.
I am able to display the dropdown but it doesn't get the contents of what I selected.
echo '<br><br><br><br><br>
<div class="Table">
<table border="2pt solid black" align="left" cellpadding="2px" bordercolor=black>
<tr>
<td width = "7%">
<div align = "left"><b>BRAND NAME</div></b>
</td>
<td width = "7%">
<div align = "left"><b>INGREDIENT</div></b>
</td>
<td width = "3%">
<div align = "left"><b>QUANTITY</div></b>
</td>
<td width = "7%">
<div align = "left"><b>MEASUREMENT</div></b>
</td>
</tr>';
for ($x = 0; $x < sizeof($rowarray); $x++) {
$query = "select R.name AS RAWNAME, I.name AS INGREDIENTNAME, R.quantity AS RAWQUANTITY from rawmaterial R JOIN ingredient I ON R.ingredient_id = I.ingredient_id where R.rawmaterial_id='{$rowarray[$x]}'";
$res = mysqli_query($dbc, $query);
while ($fetch = mysqli_fetch_array($res, MYSQL_ASSOC)) {
echo "<tr>
<td width=\"7%\">
<div align=\"left\">{$fetch['RAWNAME']}</div>
</td>
<td width=\"3%\">
<div align=\"left\">{$fetch['INGREDIENTNAME']}</div>
</td>
<td width=\"3%\">
<div align=\"left\"><input type='name' name='quantity[]' placeholder={$fetch['RAWQUANTITY']}></input></div>
</td>
<td width=\"7%\">
<div align=\"left\">";
echo "<select name = 'measure'>";
$mesr = mysqli_query($dbc, 'select measure from measure_ref');
while ($row = mysqli_fetch_array($mesr, MYSQLI_ASSOC)) {
$mes = $row['measure'];
echo '<option value ='.$mes.'>'.$mes.'</option>';
}
echo "</select>";
echo "</div>";
echo "</td>";
echo "</tr>";
}
}
echo '</table></div>';
$messarray = array();
$mes = $_POST['measure'];
$row = array();
foreach ($mes as $row) {
array_push($messarray, $row);
}
Check below points.
Make sure your dropdown is within form
As you are creating multiple dropdown you should give name with '[]'(measure[]),like you have given to 'quantity[]'.
I am using a foreach to elaborate some values scraped from a web site. It works but I have the follow problem (I put screens to explain my problem in the best way).
In the first screen, you can see that Derry City - Limerick doesn't have 1 X 2 odds
But when I get that values, my code fill empty odds with the first odds available, see the screen below:
This is the HTML code:
<table class="table-main js-tablebanner-t js-tablebanner-ntb">
<tr><th class="h-text-left" colspan="2">2. Round</th><th> </th><th class="table-main__bs">B's</th><th class="h-text-center">1</th><th class="h-text-center">X</th><th class="h-text-center">2</th></tr>
<tr>
<td class="table-main__datetime">21.03.2017 20:45</td>
<td class="h-text-left"><span>Derry City</span> - <span>Limerick</span></td>
<td class="h-text-right">
<ul class="list-tags"><li class="list-tags__item"><i class="icon icon__stream"></i><div class="list-tags__window list-tags__window--streams"><ul class="list-tags__window__in">
<li>Live streams</li>
<li>bwin</li>
<li>Sportingbet</li>
</ul></div></li></ul>
</td>
<td class="table-main__bs"> </td>
<td class="table-matches__odds" data-oid=""> </td>
<td class="table-matches__odds" data-oid=""> </td>
<td class="table-matches__odds" data-oid=""> </td>
</tr>
<tr><th class="h-text-left" colspan="2">5. Round</th><th> </th><th class="table-main__bs">B's</th><th class="h-text-center">1</th><th class="h-text-center">X</th><th class="h-text-center">2</th></tr>
<tr>
<td class="table-main__datetime">18.03.2017 15:00</td>
<td class="h-text-left"><span>Limerick</span> - <span>Finn Harps</span></td>
<td class="table-matches__odds" data-oid="2kou5xv464x0x5uaff"></td>
<td class="table-matches__odds" data-oid="2kou5xv498x0x0"></td>
<td class="table-matches__odds" data-oid="2kou5xv464x0x5uafg"></td>
</tr>
<tr>
<td class="table-main__datetime">18.03.2017 16:00</td>
<td class="h-text-left"><span>Derry City</span> - <span>Drogheda</span></td>
<td class="table-main__bs">23</td>
<td class="table-matches__odds" data-oid="2kp2nxv464x0x5uaoj"></td>
<td class="table-matches__odds" data-oid="2kp2nxv498x0x0"></td>
<td class="table-matches__odds" data-oid="2kp2nxv464x0x5uaok"></td>
</tr>
and, at least, this is my code:
$match_dates = $html->find("td[class=table-main__datetime]");
$titles = $html->find("a[class=in-match]"); // 1 per match
$odds = $html->find("td[class=table-matches__odds]/a"); // 2
function print_odd($odd) {
if (array_key_exists('data-odd', $odd->attr)) {
return $odd->attr['data-odd'];
}
return $odd->children(0)->children(0)->children(0)->attr['data-odd'];
}
$c=0; $b=0; $o=0; $z=0; // two counters
foreach ($titles as $match) {
list($num1, $num2) = explode(':', $res->innertext); // <- explode
list($home, $away) = explode('-', $titles[$z++]->innertext); // <- explode
list($date, $time) = explode('-', $match_dates[$o++]->innertext); // <- explode
$odd1 = print_odd($odds[$b++]);
$odd2 = print_odd($odds[$b++]);
$odd3 = print_odd($odds[$b++]);
$home = strip_tags($home);
$away = strip_tags($away);
$uniquefield = $home . ' ' . $away;
echo "<tr><td class='rtitle'>".
//"<td class='last-cell'>".$match_dates[$o++]->innertext. "</td> " .
"<td> ".$date.'</td><td> : </td><td>'.$time . " / " .
"<td> ".$home.'</td><td> : </td><td>'.$away . " / " .
"<td class='odds'>".$odd1 . ";" .
"".$odd2 . ";" .
"".$odd3 . "</td>" .
"".$uniquefield."</td></tr><br/>";
I have a table like this.
but I want the data on the 'debit' column is on it own place.
this is what Iwant :
this is my current code :
<?php
foreach ($jurnal->result_array() as $data){
echo "
<tr>
<td>".$data['no_akun']."</td>
<td>".$data['nm_akun']."</td>";
if ($data['nm_akun'] == 'kredit'){
echo "
<td></td>
<td>".$data['posisi_dr_cr']."</td>
";
}else{
echo "
<td>".$data['posisi_dr_cr']."</td>
<td></td>
";
}
"</tr>
";
}
?>
td tag width is the same of the content that it envelopes, so an empty td will be 0px width.
Try adding width="25%" to your td tags, like this:
EDITED:
foreach ($jurnal->result_array() as $data){
echo "
<tr>
<td width=\"25%\">".$data['no_akun']."</td>
<td width=\"25%\">".$data['nm_akun']."</td>";
if ($data['nm_akun'] == 'kredit'){
echo "
<td width=\"25%\"></td>
<td width=\"25%\">".$data['posisi_dr_cr']."</td>
";
}else{
echo "
<td width=\"25%\">".$data['posisi_dr_cr']."</td>
<td width=\"25%\"></td>
";
}
"</tr>
";
}
?>
Notice that width="25%" is typed inside a String, so double quote characters must have \ characters in order to be escaped.
Try this way. if you are using bootstrap css, you can use text-left in the class.
<?php
foreach ($jurnal->result_array() as $data){
echo "
<tr>
<td class='text-left'>".$data['no_akun']."</td>
<td class='text-left'>".$data['nm_akun']."</td>";
if ($data['nm_akun'] == 'kredit'){
echo "
<td class='text-left'></td>
<td class='text-left'>".$data['posisi_dr_cr']."</td>
";
}else{
echo "
<td class='text-left'>".$data['posisi_dr_cr']."</td>
<td class='text-left'></td>
";
}
"</tr>
";
}
?>
use the following code:
<?php
foreach ($jurnal->result_array() as $data){
echo "
<tr>
<td>".$data['no_akun']."</td>
<td>".$data['nm_akun']."</td>";
if ($data['nm_akun'] == 'kredit'){
echo "
<td> </td>
<td>".$data['posisi_dr_cr']."</td>
";
}else{
echo "
<td>".$data['posisi_dr_cr']."</td>
<td> </td>
";
}
"</tr>
";
}
?>
I have displayed sql table in html table, made a hyperlink near all fields, when i click it the whole field details should be shows in other page(ie; i show only 2 fields of sql in the table and want to show rest in another page).
admin.php
<?php
$con= mysql_connect("localhost","root","");
mysql_select_db("main",$con);
echo"<form action=\"post\" class=\"form-horizontal\" role=\"form\">";
echo "<table width='700' height='150' onclick='myFun(event)'>";
echo" <tr>
<td width='100' align='center'></td>
<td width='100' align='center'><b><u>NAME</u></b></td>
<td width='100' align='left'><b><u>E-MAIL</u></b></td>
</tr>
";
$result=mysql_query("select NAME,EMAIL from admin order by AID");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo"<td width='100' align='center'><a href='viewadmin.php?name=".$row['NAME']."'>Select</a></td>";
echo"<td width='100' align='center'>".$row['NAME']."</td>";
echo"<td width='100' align='left'>".$row['EMAIL']."</td>";
echo"</tr>";
}
echo"</table>";
echo"</form> ";
?>
viewadmin.php
<?php
$name = $_GET['name'];
$result=mysql_query("SELECT NAME,DOB,MOB,EMAIL, FROM admin WHERE NAME = $name");
if (false === $result) {
echo mysql_error();
}
else {
$row=mysql_fetch_row($result);
}
echo" <form class=\"form-horizontal\" role=\"form\">
<table width='400'>
<tr>
<td align='left'>Name</td>
<td align='left'>".$row['NAME']."</td>
</tr>
<tr>
<td align='left'>E-mail</td>
<td align='left'>".$row['EMAIL']."</td>
</tr>
<tr>
<td align='left'>D.O.B</td>
<td align='left'>".$row['DOB']."</td>
</tr>
<tr>
<td align='left'>Mobile</td>
<td align='left'>".$row['MOBILE']."</td>
</tr>
<tr>
<td align='left'>Photo</td>
<td ><img src='uploads/grumpy.jpg' height='200' width='200'></td>
</tr>
</table>";
echo"</form> ";
?>
do something like this:
admin.php
$result=mysql_query("select NAME,EMAIL from admin order by AID");
while($row=mysql_fetch_array($result)) {
echo "<tr>";
echo"<td width='100' align='center'><a href='viewadmin.php?name=".$row['NAME']."'>Select</a></td>";
echo"<td width='100' align='center'>".$row['NAME']."</td>";
echo"<td width='100' align='left'>".$row['EMAIL']."</td>";
echo"</tr>";
}
echo"</table>";
and in viewadmin.php
$name = $_GET['name'];
$result=mysql_query("SELECT * FROM admin WHERE name = $name");
$row=mysql_fetch_row($result);
echo " <form class=\"form-horizontal\" role=\"form\">
<table width='400'>
<tr>
<td align='left'>".$row['NAME']."</td>
<td align='left'></td>
</tr>
<tr>
<td align='left'>".$row['EMAIL']."</td>
<td align='left'>...";
first rename the html page by php page, then you can pass the primary key or any key of the row from first page to admin page with the help of GET.
for eg:
first.php
<?php
$result=mysql_query("select ID,NAME,EMAIL from admin order by AID"); while($row=mysql_fetch_array($result)){
?><a hre='admin.php?id="$id=<?php $row[0] ?>"'></a>
<?php
}
?>
and in the admin.php page
you can access the value like
echo $_GET['id'];
stop using MySQL and use MySQLi, this code should work
<?php
$db_connect = mysqli_connect('localhost', 'root', 'pass', 'database');
if (mysqli_connect_errno($db_connect)) {
die('Some error occurred during connection to the database');
}
$name = mysqli_real_escape_string($db_connect,$_REQUEST['name']);
if($stmt = mysqli_prepare($db_connect, 'SELECT * FROM admin WHERE name = ?')){
mysqli_stmt_bind_param($stmt, 's', $name);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if(mysqli_num_rows($result) !== 0){
$row = mysqli_fetch_assoc($result);
echo "<form class=\"form-horizontal\" role=\"form\">
<table width='400'>
<tr>
<td align='left'>".$row['NAME']."</td>
<td align='left'></td>
</tr>
<tr>
<td align='left'>".$row['EMAIL']."</td>
<td align='left'>..."
}
else{
echo 'not found';
}
}
else{
trigger_error('error:' . mysqli_errno($db_connect) . mysqli_error($db_connect));
}
?>
My code
<?php
include('ConnectToDb.php');
$query = "SELECT * FROM News WHERE NewsFlag = 1 ORDER BY PostDate DESC";
$arrCount = -1;
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$ID=$row['ID'];
$PostDate = $row['PostDate'];
$NewsHeader = stripslashes($row['NewsHeader'])
;
$NewsStart = stripslashes($row['NewsStart'])
;
echo "<hr>";
echo "<div>". date('j F Y',strtotime($PostDate)). "</div>";
echo "<p>";
$news_id = strval(sprintf("%1$04d",$ID));
$array = scanImageFolder("newsImages/newsThumbs",$news_id);
if(count($array)>0) {
echo "<img src='". $array[0]. "' alt='' />";
}
echo "<h2 style='text-align:center'><u><a href='latestnews_full.php?ID=$ID'>". $NewsHeader. "</a></u></h2>";
echo "<div style='text-align:left'><h3>";
echo $NewsStart. " ......<a href='latestnews_full.php?ID=$ID'>(more)</a><br />";
echo "<div style='text-align:center'>";
echo "</div>";
echo "</h3></div>";
}
?>
displays my data nicely on four lines with date at the top, then a picture, title and then description.
However, I want to display the data as a table like this
<table style="width: 100%">
<tr>
<td colspan="2">postDate here</td>
</tr>
<tr>
<td rowspan="2">picture here</td>
<td>newsHeader here</td>
</tr>
<tr>
<td>newsStart here</td>
</tr>
</table>
I'm not sure how to echo the table cells correctly and all of my attempts so far have resulted in a white page. Could anyone please enlighten me?
I'd suggest you to make your logic separated from your presentable part. Close the PHP tag once you are ready fetching the results, assigning var's etc, then:
<table style="width: 100%">
<?php
//yourcode
//...
//...
$NewsStart = stripslashes($row['NewsStart']);
$news_id = strval(sprintf("%1$04d",$ID));
$array = scanImageFolder("newsImages/newsThumbs",$news_id);
?>
<tr>
<td colspan="2"><?= date('j F Y',strtotime($PostDate)) ?></td>
</tr>
<tr>
<?php
if(count($array)>0) {
?>
<td rowspan="2"><img src='<?= $array[0] ?>' alt='' /></td>
<?php } ?>
<td><?= $NewsHeader ?></td>
</tr>
<tr>
<td><?= $NewsStart ?> </td>
</tr>
<?php } ?>
</table>
However, it's again not so clear, and I would suggest using a template engine. If you want I can post a code with assigning vars to Smarty and output your presentation in Smarty template