I am in the process of converting my old PHP from mysql to mysqli and am running into this error during my conversion. The code worked without throwing errors under mysql but for some reason I get the 'Undefined variable: prevcat in /xx/xx/xx/xx/xx/xx/vluchtbijtoestel.php on line 102' error now. I've tried adding $prevcat = $cat to the variables list but that then breaks the code.
My code:
<?php
define('DB_SERVER', "xxx");
define('DB_USER', "xxx");
define('DB_PASSWORD', "xxx");
define('DB_TABLE', "xxx");
// Define your colors for the alternating rows
$color1 = "#F0F8FF";
$color2 = "#FFFFFF";
$row_count = 0;
// The procedural way
$mysqli = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_TABLE);
$mysqli->set_charset("utf8");
$mysqli->set_charset("utf8");
$mysqli->query("SET NAMES 'utf8'");
if (mysqli_connect_errno($mysqli)) {
trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR);
}
$query = "
SELECT vg.gegevenID, lvm.luchtvaartmaatschappij, lvm.sm_logo, vg.vertrekdatum2, vg.vertrekluchthaven, vg.aankomstluchthaven, vg.toestel, vg.inschrijvingnmr, vlg.vliegtuignaam, vg.vluchtnmr, t.toestel AS toestelnaam, lh.luchthavencode, lh.luchthavennaam, lh.countryflag, lh2.luchthavencode AS aankomstluchthavencode, lh2.countryflag AS countryflagaankomst, vlg.erlr, vlg.firstflight, DATEDIFF(vlg.firstflight,vg.vertrekdatum2) Age1, lh2.luchthavennaam AS aankomstnaam, CONCAT(t.toestel,' ', vlg.erlr) as toestelmeterlr
FROM (tbl_vliegtuiggegevens vlg
INNER JOIN (tbl_luchtvaartmaatschappij lvm INNER JOIN tbl_vluchtgegevens vg ON lvm.luchtvaartmaatschappijID = vg.luchtvaartmaatschappij) ON (vlg.inschrijvingnmr = vg.inschrijvingnmr) AND (vlg.lvmID = lvm.luchtvaartmaatschappijID)) INNER JOIN tbl_toestel t ON vg.toestel = t.toestelID
LEFT JOIN tbl_luchthaven lh
ON vg.vertrekluchthaven = lh.luchthavenID
LEFT JOIN tbl_luchthaven lh2
ON vg.aankomstluchthaven = lh2.luchthavenID
GROUP BY lvm.luchtvaartmaatschappij, toestelmeterlr, vg.inschrijvingnmr, vg.vertrekdatum2
ORDER BY lvm.luchtvaartmaatschappij, toestelmeterlr, vg.vertrekdatum2 DESC, vg.inschrijvingnmr; ";
$result = mysqli_query($mysqli, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($mysqli), E_USER_ERROR);
echo "
<table width='100%' border='0'>
<tr>
<td colspan='3'><strong>Luchtvaartmaatschappij</strong></td>
<td width='17%'> </td>
<td width='12%'> </td>
<td width='19%'> </td>
<td width='28%'> </td>
</tr>
<tr>
<td width='2%'> </td>
<td colspan='3'><strong>Toestel</strong></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td width='3%'> </td>
<td width='19%'><strong>vertrekdatum</strong></td>
<td><strong>vliegroute</strong></td>
<td><strong>registratie</strong></td>
<td><strong>vliegtuignaam</strong></td>
<td><strong>vliegtuig leeftijd op reisdatum</strong></td>
</tr>
</table>
";
if($result) {
while($row = mysqli_fetch_assoc($result)) {
$row_color = ($row_count % 2) ? $color1 : $color2;
$date1 = date_create($row['firstflight']);
$date2 = date_create($row['vertrekdatum2']);
$interval = date_diff($date1, $date2);
$cat = $row['luchtvaartmaatschappij'];
$subcat = $row['toestelmeterlr'];
$item = $row['inschrijvingnmr'];
if($cat != $prevcat){
echo " <table width='100%' border='0'>";
echo " <tr>";
echo " <td><br /><hr></td>";
echo " </tr>";
echo " <tr>";
echo " <td><strong><span class='style4'><img src='http://globe-trekking.com/vg/img/logos/sm/".$row['sm_logo']."'> " .$cat. "</strong></span> <br /></td>";
echo " </tr>";
echo "</table>";
echo '<span style="color: #0A0094; font-size: 16px;"> '. $subcat.'</span><br />';//if the category has changed, we also want to show the new subcat
}elseif($subcat != $prevsubcat){
echo '<br /><span style="color: #0A0094; font-size: 16px;"> ' .$subcat.'</span><br />';
}
echo " <table width='1093' border='0' cellspacing='0'>";
echo " <tr>";
echo " <td width='75'> </td>";
echo " <td width='200' bgcolor='$row_color'>" .date("d-M-Y H:i", strtotime($row['vertrekdatum2']))."</td>";
echo " <td width='70' bgcolor='$row_color'><img src='http://globe-trekking.com/vg/img/flags/".$row['countryflag']."'> <abbr title=\"".htmlspecialchars($row['luchthavennaam'])."\">".$row['luchthavencode']."</abbr></td>";
echo " <td width='70' bgcolor='$row_color'> naar </td>";
echo " <td width='130' bgcolor='$row_color'><img src='http://globe-trekking.com/vg/img/flags/".$row['countryflagaankomst']."'> <abbr title=\"".htmlspecialchars($row['aankomstnaam'])."\">".$row['aankomstluchthavencode']."</abbr></td>";
echo " <td width='150' bgcolor='$row_color'>".$row['inschrijvingnmr']."</td>";
echo " <td width='250' bgcolor='$row_color'>".$row['vliegtuignaam'] ."</td>";
echo " <td width='250' bgcolor='$row_color'>" . $interval->y . " jaar en " . $interval->m." maanden </td>";
echo " </tr>";
echo "</table>";
$prevcat = $cat;
$prevsubcat = $subcat;
// Add 1 to the row count
$row_count++;
}
}
mysqli_close($mysqli);
?>
put your code .. you are using $precat and $prevsubcat in your if conditions before declaring and defining it.
$prevcat = $cat;
$prevsubcat = $subcat;
after
$cat = $row['luchtvaartmaatschappij'];
$subcat = $row['toestelmeterlr'];
like this
$cat = $row['luchtvaartmaatschappij'];
$subcat = $row['toestelmeterlr'];
$prevcat = $cat;
$prevsubcat = $subcat;
Put
$prevcat = '';
$prevsubcat = '';
Juste before "While" expression
Regards
Related
Here is what I have for my php coding.
<?php
$USER_NAME = ' ';
$USER_PASSWORD = ' ';
$DB_SERVER = " ";
$DB_NAME = $USER_NAME."_db";
$conn = mysqli_connect($DB_SERVER, $USER_NAME, $USER_PASSWORD, $DB_NAME);
$result = mysqli_query($conn," SELECT * FROM employee,workson where workson.ESSN = employee.SSN and workson.Projnum ='" . $_GET["PNO"] . "'");
$notincluded = mysqli_query($conn, "SELECT SSN, FName, Lname FROM employee where NOT EXISTS (SELECT * FROM workson WHERE employee.SSN = workson.ESSN and workson.Projnum ='" . $_GET["PNO"] . "')") ;
if (!$conn) {
echo "Could not connect: ";
echo mysqli_connect_error(); }
?>
<table border = "1">
<b>Employee List: <b>
<td>Project Number</td>
<td>SSN</td>
<td>First Name</td>
<td>Last Name</td>
<td>Working Hours</td>
<td>Delete</td>
<td>Update</td>
</tr>
<?php
$i=0;
while($row = mysqli_fetch_array($result)) {
?>
<td style = "text-align:center; vertical-align: middle;"> <?php echo $row["Projnum"]; ?></td>
<td style = "text-align:center; vertical-align: middle;"> <?php echo $row["SSN"]; ?></td>
<td style = "text-align:center; vertical-align: middle;"> <?php echo $row["FName"]; ?></td>
<td style = "text-align:center; vertical-align: middle;"> <?php echo $row["Lname"]; ?></td>
<td style = "text-align:center; vertical-align: middle;"> <?php echo $row["NoHours"]; ?> </td>
<td>Delete</td>
<td>Update Hours</td>
</tr>
<?php
$i++;
}
?>
</table>
<br>
<br>
<form method=POST action="http://mkimas.student.ust.hk/cgi-bin/mini_project_5.php">
<b> Employee not included : </b>
<?php
$notincluded = mysqli_query($conn,
"SELECT SSN, FName, Lname FROM employee where NOT EXISTS (SELECT * FROM workson WHERE employee.SSN = workson.ESSN and workson.Projnum ='" . $_GET["PNO"] . "')") ;
$employees = mysqli_fetch_all($notincluded);
$projnum = $_GET["PNO"];
print("<select name='Employees' id='employees'>");
foreach($employees as $employee){
//You can use the index 0, which corresponds with the first selected column in query
print("<option value='$employee[0]'>$employee[0]</option>");
}
print("</select>")
?>
<br>
Input the amount of hours and which project number new employee worked on: <br>
Hours: <input name=hours type =text> <br>
<input type=submit value="Submit">
</form>
For the second part of my php, a selection list of employees not included in the table above is printed. Then, I have the php file that has a SQL query that inserts the not included employee.
<?php
echo "Start \n";
echo "<hr>";
$USER_NAME = " ";
$USER_PASSWORD = " ";
$DB_SERVER = " ";
$DB_NAME = $USER_NAME."_db";
$ESSN = $_POST["Employees"];
$Projnum = $_POST["projnum"];
$NoHours = $_POST["hours"];
$conn = mysqli_connect($DB_SERVER, $USER_NAME, $USER_PASSWORD, $DB_NAME);
if (!$conn) {
echo "Could not connect: ";
echo mysqli_connect_error(); }
$sql="insert into workson(ESSN, Projnum, NoHours) values('$ESSN', '$Projnum', '$NoHours')";
$result=mysqli_query($conn,$sql);
if($result){
echo "insert success"; }
else{
echo "insert fail"; }
mysqli_close($conn);
?>
Somehow, my coding always outputs "insert fail". What might be the problem?
Have you tried :
$sql="INSERT INTO workson(ESSN, Projnum, NoHours) VALUES (".$ESSN.", ".$Projnum.", ".$NoHours.")";
Could you dump the result ?
Regards,
I'm very new to PHP and MySQLI, however, I have been dabbling with them for a couple of years.
I am working on adding a search function for some photos I have on my website based off of 3 criteria.
I've been successful in implementing the script on a different page, which does not include the syntax for the page limits. However, now, when I add in my $where_stmt code, I end up with some errors, and I believe it has to do with the placement of a needed }.
The script in question is:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
if (!defined('DB_SERVER')) define('DB_SERVER', 'xxx');
if (!defined('DB_USER')) define('DB_USER', 'xxx');
if (!defined('DB_PASSWORD')) define('DB_PASSWORD', 'xxx');
if (!defined('DB_TABLE')) define('DB_TABLE', 'xxx');
// The procedural way
$mysqli = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_TABLE);
$mysqli->set_charset("utf8");
$mysqli->query("SET NAMES 'utf8'");
if (mysqli_connect_errno($mysqli)) {
trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR);
}
// This first query is just to get the total count of rows
$sql = "SELECT COUNT(*) FROM tbl_photos";
$query = mysqli_query($mysqli, $sql);
$row = mysqli_fetch_row($query);
// Here we have the total row count
$rows = $row[0];
// This is the number of results we want displayed per page
$page_rows = 16;
// This tells us the page number of our last page
$last = ceil($rows/$page_rows);
// This makes sure $last cannot be less than 1
if($last < 1){
$last = 1;
}
// Establish the $pagenum variable
$pagenum = 1;
// Get pagenum from URL vars if it is present, else it is = 1
if(isset($_GET['pn'])){
$pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']);
}
// This makes sure the page number isn't below 1, or more than our $last page
if ($pagenum < 1) {
$pagenum = 1;
} else if ($pagenum > $last) {
$pagenum = $last;
}
// This sets the range of rows to query for the chosen $pagenum
$limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
if(isset($_POST['submit']))
if(isset($_GET['go']))
if(isset($_REQUEST['submited'])) {
$tid = $_POST['tID'];
$lvmid = $_POST['lvmID'];
$lid = $_POST['lID'];
$where_stmt="";
// query only for LuchtvaartmaatschappijID (LVMID)
if((isset($lvmid) && !empty($lvmid)) && (!isset($tid) || empty($tid)) && (!isset($lid) || empty($lid)))
{
$where_stmt="WHERE lvm.luchtvaartmaatschappijID='".$lvmid."'";
}
// query only for ToestelID
elseif((isset($tid) && !empty($tid)) && (!isset($lvmid) || empty($lvmid)) && (!isset($lid) || empty($lid)))
{
$where_stmt="WHERE t.toestelID = '".$tid."'";
}
// query only for luchthaven
elseif((isset($lid) && !empty($lid)) && (!isset($lvmid) || empty($lvmid)) && (!isset($tid) || empty($tid)))
{
$where_stmt="WHERE img_location = '".$lid."'";
}
// query only for Luchtvaartmaatschappij and Toestel
elseif((isset($lvmid) && !empty($lvmid)) && (isset($tid) || !empty($tid)) && (!isset($lid) || empty($lid)))
{
$where_stmt="WHERE lvm.luchtvaartmaatschappijID='".$lvmid."' and t.toestelID='".$tid."'";
}
// query only for Luchtvaartmaatschappij and luchthaven
elseif((isset($lvmid) && !empty($lvmid)) && (isset($lid) || !empty($lid)) && (!isset($tid) || empty($tid)))
{
$where_stmt="WHERE lvm.luchtvaartmaatschappijID='".$lvmid."' and img_location = '".$lid."'";
}
// query for luchtvaartmaatschappij, toestel and luchthaven
elseif((isset($lvmid) && !empty($lvmid)) && (isset($tid) && !empty($tid)) && (isset($lid) && !empty($lid)))
{
$where_stmt="WHERE lvm.luchtvaartmaatschappijID='".$lvmid."' and t.toestelID='".$tid."' and img_location = '".$lid."'";
}
else
{
//where statement should be excluded as no filters are available
}
// This is your query again, it is for grabbing just one page worth of rows by applying $limit
$sql = "
SELECT randimgID, img_location, img_lvm, img_file, img_nmr, img_t, t.toestel, l.luchthavennaam, lvm.luchtvaartmaatschappij, lvm.luchtvaartmaatschappijID, t.toestelID
FROM tbl_photos p
LEFT JOIN tbl_luchthaven l
ON p.img_location = l.luchthavenID
LEFT JOIN tbl_luchtvaartmaatschappij lvm
ON p.img_lvm = lvm.IATAcode
LEFT JOIN tbl_toestel t
ON p.img_t = t.toestelID
$where_stmt
ORDER BY lvm.luchtvaartmaatschappij, t.toestel ASC, p.img_nmr ASC $limit";
$query = mysqli_query($mysqli, $sql);
/* determine number of rows result set */
$row_cnt = mysqli_num_rows($query);
// This shows the user what page they are on, and the total number of pages
$textline1 = "beelden (<b>$rows</b>)";
$textline2 = "Page <b>$pagenum</b> of <b>$last</b>";
// Establish the $paginationCtrls variable
$paginationCtrls = '';
// If there is more than 1 page worth of results
if($last != 1){
/* First we check if we are on page one. If we are then we don't need a link to
the previous page or the first page so we do nothing. If we aren't then we
generate links to the first page, and to the previous page. */
if ($pagenum > 1) {
$previous = $pagenum - 1;
$paginationCtrls .= '<li class="page-item"><a class="page-link" href="'.$_SERVER['PHP_SELF'].'?pn='.$previous.'">vorige</a> </li>';
// Render clickable number links that should appear on the left of the target page number
for($i = $pagenum-4; $i < $pagenum; $i++){
if($i > 0){
$paginationCtrls .= '<li class="page-item"><a class="page-link" href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> </li>';
}
}
}
// Render the target page number, but without it being a link
$paginationCtrls .= '<li class="page-item active">
<a class="page-link" href="#">'.$pagenum.' <span class="sr-only">(current)</span></a>
</li>';
// Render clickable number links that should appear on the right of the target page number
for($i = $pagenum+1; $i <= $last; $i++){
$paginationCtrls .= '<li class="page-item"><a class="page-link" href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> </li> ';
if($i >= $pagenum+4){
break;
}
}
// This does the same as above, only checking if we are on the last page, and then generating the "Next"
if ($pagenum != $last) {
$next = $pagenum + 1;
$paginationCtrls .= '<li class="page-item"><a class="page-link" href="'.$_SERVER['PHP_SELF'].'?pn='.$next.'">volgende</a> </li>';
}
}
$list = '';
$items_in_row = 2 ;
$index = 0 ;
echo "<table width='100%' cellspacing='1' border='0'>
<tr>";
while($row = mysqli_fetch_assoc($query)) {
$img_location = $row['luchthavennaam'];
$img_lvm = $row['img_lvm'];
$l = htmlspecialchars($row['luchtvaartmaatschappij']);
$lvmID = $row['luchtvaartmaatschappijID'];
$img_nmr = $row['img_nmr'];
$t = $row['toestel'];
$tid = $row['toestelID'];
$f = $row['img_file'];
$rID = $row['randimgID'];
$img_file = $row['img_file'];
$image = "http://globe-trekking.com/vg/img/gallery/$img_lvm/$img_file";
$link = "http://globe-trekking.com/vg/gallery/details.php?pid=$rID&lvmID=$lvmID&in=$img_nmr";
$index++ ;
echo "<td width='370' align='left' valign='top' bgcolor='#292960'> ";
echo "<table width='540' border='0' cellpadding='0' cellspacing='0'>";
echo "<tbody>";
echo " <tr>";
echo " <td height='15' colspan='3' bgcolor='#292960'></td>";
echo " </tr>";
echo " <tr>";
echo " <td height='15' colspan='3' bgcolor='#000033'></td>";
echo " </tr>";
echo "<tr>";
echo " <td width='15' bgcolor='#000033'> </td>";
echo " <td bgcolor='#000033'><a href='" . $link ."'><img src='".$image."' width='510'></a></td>";
echo " <td width='15' bgcolor='#000033'></td>";
echo "</tr>";
echo "<tr>";
echo " <td bgcolor='#000033'> </td>";
echo " <td bgcolor='#000033'><table width='510' border='0' align='center' cellpadding='0' cellspacing='0'>";
echo " <tr>";
echo " <td height='15' colspan='2' valign='top' style='text-align: left'> </td>";
echo " </tr>";
echo " <tr>";
echo " <td width='72%' valign='top' style='text-align: left'><span style='font-size: 18px; color: #DEDEDE'><a class='airline' href='gallery_lvm.php?lvmid=$lvmID'>" . $l . "</a></span></td>";
echo " <td width='28%' style='text-align: left'><span style='font-size: 14.5px; color: #DEDEDE'>Reg: <a class='airline' href='gallery_reg.php?reg=$img_nmr'>" . $img_nmr . "</a></span></td>";
echo " </tr>";
echo " <tr>";
echo " <td height='10' colspan='2' valign='top' style='text-align: left'></td>";
echo " </tr>";
echo " <tr>";
echo " <td valign='top' style='text-align: left'><span style='font-size: 14.5px; color: #DEDEDE'><a class='airline' href='gallery_t.php?tid=$tid'>" . $t . "</a></span></td>";
echo " <td style='text-align: left'> </td>";
echo " </tr>";
echo " <tr>";
echo " <td height='10' colspan='2' valign='top' style='text-align: left'></td>";
echo " </tr>";
echo " <tr>";
echo " <td colspan='2' valign='top' style='text-align: left'><span style='font-size: 14.5px; color: #DEDEDE'>" . $img_location . "</span><br>
<br>
</td>";
echo " </tr>";
echo " <tr>";
echo " <td style='text-align: left'> </td>";
echo " <td style='text-align: left'> </td>";
echo " </tr>";
echo " </table></td>";
echo " <td bgcolor='#000033'> </td>";
echo "</tr>";
echo "<tr>";
echo " <td> </td>";
echo " <td> </td>";
echo " <td> </td>";
echo "</tr>";
echo " </tbody>";
echo " </table>";
echo " </td>";
if ($index%$items_in_row == 0){
echo " </tr>";
echo " <tr>";
}
}
echo " </tr>";
echo " </table>";
// Close your database connection
mysqli_close($mysqli);
?>
<br />
<nav aria-label="Page Navigation">
<ul class="pagination justify-content-center">
<div class="pagination"><?php echo $paginationCtrls; ?></div>
</ul>
</nav>
<br />
</div>
<br />
<br />
</div>
<?php include '../includes/menu/footer.php'; ?>
</body>
</html>
When I add it after the last else statement, I end up with an error that indicate
Notice: Undefined variable: where_stmt in /xxx/xxx/public_html/vg/gallery/search_post.php on line 174
// query for luchtvaartmaatschappij, toestel and luchthaven
elseif((isset($lvmid) && !empty($lvmid)) && (isset($tid) && !empty($tid)) && (isset($lid) && !empty($lid)))
{
$where_stmt="WHERE lvm.luchtvaartmaatschappijID='".$lvmid."' and t.toestelID='".$tid."' and img_location = '".$lid."'";
}
else
{
//where statement should be excluded as no filters are available
}
}
If I add it just before the mysqli_close() then it throws an error of:
PHP Notice: Undefined variable: paginationCtrls in
/xxx/xxx/public_html/vg/gallery/search_post.php on line 325
If I leave it out all together I get the following red x error in the web editor my hosting company provides me with:
Unexpected syntax, error $E0F
At this point, I'm not sure where this should be placed.
I should note that I can get the code to work when I get rid of the $where_stmt and the code above the $sql query.
I can recommend you to have a look at ORM libraries like http://propelorm.org/documentation/reference/model-criteria.html#finding-objects to avoid handwritten SQL and concatenated where clauses.
Also make sure that $paginationCtrls is declared before using it.
I have a test query I am performing and it seems to be running OK, however not returning any data within the rows of the tables when using a varible passed or a direct set year for the table
<?
$curyr = date("Y");
isset($_GET['year']) ? $year = $_GET['year'] : $year = "";
$server = $_SERVER['PHP_SELF'];
$dbhost = "localhost";
$dbuname = "";
$dbpass = "";
$dbname = "";
$conn = new mysqli($dbhost,$dbuname,$dbpass,$dbname);
if($conn->connect_errno):
die("$conn->connect_error \n");
endif;
echo ("<title>$year</title>");
if (($year >= 2001) && ($year <=$curyr)) {
echo ("
<table border='0' align='center' width='100%'>
<tr>
<td>
<table border='1' align='center' width='60%' style='border:1 solid #000000; border-collapse: collapse'>
<tr>
<th align='center' colspan='5'>
DETAIL
</th>
</tr>");
$query = "SELECT c.* , p.* FROM $year c, dataset p WHERE c.id = p.id ORDER BY p.name ASC";
$r = $conn->query($query);
while ($row = $r->fetch_assoc()) {
echo ("
<tr>
<td>
$row[namepre]$row[name]
</td>
<td>
</td>
<td>
TEST
</td>
<td>
</td>
</tr>");
}
echo ("
</table>
</td>
</tr>
</table>");
} else {
echo ("ERROR NO ROWS");
}
$conn->close();
?>
I'm returning the "detail" portion of the top of the sample table but nothing else. This is just basic but wondering where I'm possibly missing something.
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.)
I am using an open source calendar to display events, I am having a trouble to add extra fields to event display form. Could anyone please indicate where I need to add code so more fields can be displayed.
Please could anyone kindly help me.
Many Thanks.
Here is the code for displaying the events:
<?php
require("config.php");
require("./lang/lang." . LANGUAGE_CODE . ".php");
require("functions.php");
$auth = auth();
$id = $_GET['id'];
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());
$sql = "SELECT d, m, y FROM " . DB_TABLE_PREFIX . "mssgs WHERE id=" . $id;
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
$d = $row["d"];
$m = $row["m"];
$y = $row["y"];
$dateline = $lang['months'][$m-1] . " $d, $y";
$wday = date("w", mktime(0,0,0,$m,$d,$y));
writeHeader($m, $y, $dateline, $wday, $auth);
// display selected posting first
writePosting($id, $auth);
// give some space
echo '<img src="images/clear.gif" width="1" height="25" border="0"><br clear="all">';
// query for rest of this day's postings
$sql = "SELECT id, start_time FROM " . DB_TABLE_PREFIX . "mssgs ";
$sql .= "WHERE y = " . $y . " AND m = " . $m . " AND d = " . $d . " AND id != $id ";
$sql .= "ORDER BY start_time ASC";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result)) {
echo '<span class="display_header">' . $lang['otheritems'] . '</span>';
echo '<br clear="all"><img src="/images/clear.gif" width="1" height="3" border="0"><br clear="all">';
// display rest of this day's postings
while ($row = mysql_fetch_array($result)) {
writePosting($row[0], $auth);
echo '<img src="images/clear.gif" width="1" height="12" border="0"><br clear="all">';
}
}
echo "</body></html>";
function writeHeader($m, $y, $dateline, $wday, $auth)
{
global $lang;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>phpEventCalendar: Event Display</title>
<link rel="stylesheet" type="text/css" href="css/popwin.css">
<?php if ($auth) { ?>
<script language="JavaScript">
function deleteConfirm(eid) {
var msg = "<?php echo $lang['deleteconfirm'] ?>";
if (confirm(msg)) {
opener.location = "eventsubmit.php?flag=delete&id=" + eid + "&month=<?php echo $m ?>&year=<?php echo $y ?>";
window.setTimeout('window.close()', 1000);
} else {
return;
}
}
</script>
<?php } ?>
</head>
<body>
<!-- selected date -->
<table cellspadding="0" cellspacing="0" border="0" width="300" bgcolor="#CCFFCC">
<tr>
<td bgcolor="#CCFFCC"><span bgcolor="#CCFFCC" class="display_header"><?php echo $dateline ?></span></td>
<td bgcolor="#CCFFCC" align="right"><span class="display_header"><?php echo $lang['days'][$wday] ?></span></td>
</tr>
</table>
<img src="images/clear.gif" width="1" height="3" border="0"><br clear="all">
<?php
}
function writePosting($id, $auth)
{
global $lang;
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());
$sql = "SELECT y, m, d, title, text, start_time, end_time, ";
$sql .= DB_TABLE_PREFIX . "users.uid, fname, lname, ";
if (TIME_DISPLAY_FORMAT == "12hr") {
$sql .= "TIME_FORMAT(start_time, '%l:%i%p') AS stime, ";
$sql .= "TIME_FORMAT(end_time, '%l:%i%p') AS etime ";
} elseif (TIME_DISPLAY_FORMAT == "24hr") {
$sql .= "TIME_FORMAT(start_time, '%H:%i') AS stime, ";
$sql .= "TIME_FORMAT(end_time, '%H:%i') AS etime ";
} else {
echo "Bad time display format, check your configuration file.";
}
$sql .= "FROM " . DB_TABLE_PREFIX . "mssgs ";
$sql .= "LEFT JOIN " . DB_TABLE_PREFIX . "users ";
$sql .= "ON (" . DB_TABLE_PREFIX . "mssgs.uid = " . DB_TABLE_PREFIX . "users.uid) ";
$sql .= "WHERE id = " . $id;
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$title = stripslashes($row["title"]);
$body = stripslashes(str_replace("\n", "<br />", $row["text"]));
$postedby = $lang['postedby'] . ": " . $row['fname'] . " " . $row['lname'];
if (!($row["start_time"] == "55:55:55" && $row["end_time"] == "55:55:55")) {
if ($row["start_time"] == "55:55:55")
$starttime = "- -";
else
$starttime = $row["stime"];
if ($row["end_time"] == "55:55:55")
$endtime = "- -";
else
$endtime = $row["etime"];
$timestr = "$starttime - $endtime";
} else {
$timestr = "";
}
if ($auth == 2 || ($auth != 0 && $_SESSION['authdata']['uid'] == $row['uid'])) {
$editstr = "<span class=\"display_edit\">";
$editstr .= "[edit] ";
$editstr .= "[delete] </span>";
} else {
$editstr = "";
}
?>
<table cellspacing="0" cellpadding="0" border="0" width="300" bgcolor="#CCFFCC">
<tr><td bgcolor="#000000">
<table cellspacing="1" cellpadding="1" border="0" width="100%">
<tr>
<td class="display_title_bg" bgcolor="#CCFFCC"><table bgcolor="#CCFFCC" cellspacing="0" cellpadding="0" border="0" width="100%"><tr>
<td bgcolor="#CCFFCC" width="100%"><span class="display_title"> <?php echo $title ?></span></td>
<td bgcolor="#CCFFCC"><img src="images/clear.gif" width="20" height="1" border="0"></td>
<td bgcolor="#CCFFCC" align="right" nowrap="yes"><span class="display_title"><?php echo $timestr ?> </span></td>
</tr></table></td>
</tr>
<tr bgcolor="#CCFFCC"><td class="display_txt_bg" bgcolor="#CCFFCC">
<table cellspacing="1" cellpadding="1" border="0" width="100%" bgcolor="#CCFFCC">
<tr bgcolor="#CCFFCC">
<td bgcolor="#CCFFCC"><span class="display_txt"><?php echo $body ?></span></td>
</tr>
<tr bgcolor="#CCFFCC">
<td bgcolor="#CCFFCC"align="right"><span class="display_user"><?php echo $postedby ?></td>
</tr>
<tr bgcolor="#CCFFCC">
<td align="right" bgcolor="#CCFFCC"><?php echo $editstr ?></td>
</tr>
</table>
</td></tr>
</table>
</td></tr></table>
<?php
}
?>
To the best of my understanding writePosting function does most of the job and you need to enhance it to display more info about current event.
I've added a new table row at the end of this code sample to illustrate the idea.
<tr bgcolor="#CCFFCC">
<td bgcolor="#CCFFCC"><span class="display_txt"><?php echo $body ?></span></td>
</tr>
<tr bgcolor="#CCFFCC">
<td bgcolor="#CCFFCC"align="right"><span class="display_user"><?php echo $postedby ?></td>
</tr>
<tr bgcolor="#CCFFCC">
<td align="right" bgcolor="#CCFFCC"><?php echo $editstr ?></td>
</tr>
<tr bgcolor="#CCFFCC">
<td align="right" bgcolor="#CCFFCC"><?php echo "some extra info" ?></td>
</tr>