I have a data table to show on the table one row is called "address". There are only two types of address can be output "dhaka" and "yaka" . I want to show the font colour as red when the output is "dhaka" and green when the output is "yaka".
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dashboard</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js"></script>
<style type="text/css">
.wrapper{
width: 650px;
margin: 0 auto;
}
.page-header h2{
margin-top: 0;
}
table tr td:last-child a{
margin-right: 15px;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</head>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<?php
require_once "config.php";
$sql = "SELECT * FROM student_record";
if($result = mysqli_query($conn, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class='table table-bordered table-striped table-hover '>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>";
echo "<th>Name</th>";
echo "<th>Address</th>";
echo "<th>Marks</th>";
echo "<th>Action</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['marks'] . "</td>";
echo "<td>";
echo "<a href='read.php?id=". $row['id'] ."' title='View
Record' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
echo "<a href='update.php?id=". $row['id'] ."' title='Update
Record' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
echo "<a href='delete.php?id=". $row['id'] ."' title='Delete
Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
mysqli_free_result($result);
} else{
echo "<p class='lead'><em>No records were found.</em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
}
mysqli_close($conn);
?>
<form method="post" action="search1.php?go" id="searchform">
<input type="text" name="name">
<input type="submit" name="submit" value="Search">
</form>
</div>
</div>
</div>
</div>
</body>
</html>
You need to actually use if elseif statements:-
<?php
if ($row['address'] == 'dhaka') {
$color = 'RED';
} elseif ($row['address'] == 'yaka') {
$color = 'GREEN';
}
echo "<td><span style=\"color: $color\">" . $row['address'] . "</span></td>";
Please try to include this code inside while loop
if($row['address'] =='dhaka'){$color='red';}
else{$color='green';}
And update the address line with
echo "<td style='color:'.$color.'>" . $row['address'] . "</td>";
Related
So I have finished my page and want to list all the data in my database for the current customer id selected and I can only seem to get the first row in the DB to list, I can't get all of them.
I have tried a while loop but I just can't seem to get the logic. Any help would be appreciated
Here is the entire code for the page. I want to use the last table on the page to show all the customer data.
I have labeled it with a comment if you are looking for the section im referring to.
// Display all data for customer from db. -- cant seem to figure this part out [while loop?]
<?php
// Check existence of id parameter before processing further
if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){
// Include config file
require_once "../includes/config.php";
// Prepare a select statement
$sql = "SELECT * FROM customers, orders WHERE customers.id = orders.customerId AND customers.id = ?";
if($stmt = mysqli_prepare($con, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "i", $param_id);
// Set parameters
$param_id = trim($_GET["id"]);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
$result = mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
// Retrieve individual field value
$customerId = $row['customerId'];
$name = $row['name'];
$address = $row['address'];
$phone = $row['phone'];
$email = $row['email'];
$other1 = $row['other1'];
$other2 = $row['other2'];
$notStartedCheckbox = $row['notStartedCheckbox'];
$dateToWork = $row['dateToWork'];
$finishedCheckbox = $row['finishedCheckbox'];
$dateTimeFinished = $row['dateTimeFinished'];
$paidCheckbox = $row['paidCheckbox'];
$dateTimePaid = $row['dateTimePaid'];
$paidWith = $row['paidWith'];
$notes = $row['notes'];
} else{
// URL doesn't contain valid id parameter. Redirect to error page
header("location: error.php");
exit();
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>View Record</title>
<!-- stylesheets -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- scripts -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.1/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="https://kit.fontawesome.com/16d3fe3a77.js" crossorigin="anonymous"></script>
<style>
.wrapper{
width: 80%;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div>
<h3 class="mt-5 mb-3"><?php echo $row['name'] . ' | ' . $row['address'] . ' | ' . $row['phone'] . ' | ' . $row['email'] . ' ' . $row['other1'] . ' ' . $row['other2'] ; ?></h3>
<!-- Submit a form that adds a new job for a customer -->
<form action="newWorkOrder.php" method="post">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Customer ID (Auto)</th>
<th>Started</th>
<th>Work Date</th>
<th>Service</th>
<th>Finished</th>
<th>Finished Date/Time</th>
<th>Paid</th>
<th>Paid Date/Time</th>
<th>Paid With</th>
<th>Notes</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="radio" checked name="customerId" id="customerId" value="<?php echo $row['customerId'] ?>"></td>
<td><input type="checkbox" name="notStartedCheckbox" id="notStartedCheckbox" value="0"></td>
<td><input type="date" name="dateToWork" id="dateToWork"></td>
<td>
<select name="service" id="service">
<option value="mowing">Mowing</option>
</select>
</td>
<td><input type="checkbox" name="finishedCheckbox" id="finishedCheckbox" value="0"></td>
<td><input type="datetime-local" name="dateTimeFinished" id="dateTimeFinished"></td>
<td><input type="checkbox" name="paidCheckbox" id="paidCheckbox" value="0"></td>
<td><input type="datetime-local" name="dateTimePaid" id="dateTimePaid"></td>
<td><input type="text" name="paidWith" id="paidWith"></td>
<td><input type="text" name="notes" id="notes"></td>
<td><input type="submit" value="submit"></td>
</tr>
</table>
</form>
<hr>
<!-- Display the table -->
<?php
echo "<table class='table table-bordered table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<th>Started</th>";
echo "<th>Work Date</th>";
echo "<th>Service</th>";
echo "<th>Finished</th>";
echo "<th>Finished Date/Time</th>";
echo "<th>Paid</th>";
echo "<th>Paid Date/Time</th>";
echo "<th>Paid With</th>";
echo "<th>Notes</th>";
echo "</tr>";
echo "</thead>";
// Display all data for customer from db. -- cant seem to figure this part out [while loop?]
echo "<tbody>";
echo "<tr>";
echo "<td>" . $row['notStartedCheckbox'] . "</td>";
echo "<td>" . $row['dateToWork'] . "</td>";
echo "<td>" . $row['service'] . "</td>";
echo "<td>" . $row['finishedCheckbox'] . "</td>";
echo "<td>" . $row['dateTimeFinished'] . "</td>";
echo "<td>" . $row['paidCheckbox'] . "</td>";
echo "<td>" . $row['dateTimePaid'] . "</td>";
echo "<td>" . $row['paidWith'] . "</td>";
echo "<td>" . $row['notes'] . "</td>";
echo "</tr>";
echo "</table>";
?>
<br>
<p>Back</p>
</div>
</div>
</div>
</div>
</body>
</html>
Here is the section I can't get to work properly, it will display all rows after I submit a new form, but won't show any pre-existing data from my database.
while($row = mysqli_fetch_array($result) ){
echo "<tr>";
if($row['notStartedCheckbox'] == true) {
echo "<td>" . 'Started' . "</td>";
} else {
echo "<td style='color: red'>Not Started</td>";
}
echo "<td>" . $row['dateToWork'] . "</td>";
echo "<td>" . $row['service'] . "</td>";
if($row['finishedCheckbox'] == true) {
echo "<td>" . 'Finished' . "</td>";
} else {
echo "<td style='color: red'>Not Finished</td>";
}
echo "<td>" . $row['dateTimeFinished'] . "</td>";
if($row['paidCheckbox'] == true) {
echo "<td>" . 'Paid' . "</td>";
} else {
echo "<td style='color: red'>Not Paid</td>";
}
echo "<td>" . $row['dateTimePaid'] . "</td>";
echo "<td>" . $row['paidWith'] . "</td>";
echo "<td>" . $row['notes'] . "</td>";
echo "</tr>";
}
When I click the delete button it should delete the user from that row from the Database. I also want help for my modify button in this table if I click the modify button it should change the user type (Admin, Chief, user). I already tried everything but I don't know how a can solve it that's why I'm asking your help.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pannel</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<style type="text/css">
body {
font: 14px sans-serif;
text-align: center;
}
</style>
</head>
<body>
<div class="page-header">
<h1> Admin Pannel</h1>
</div>
<div>
</div>
</body>
</html>
<?php
session_start();
require 'config.php';
$strSQL = "SELECT username, email, type FROM benutzer";
$rs = mysqli_query($link, $strSQL);
echo "<table border='1' style='margin: 0 auto'>
<tr>
<th class='text-center'>Name / Vorname</th>
<th class='text-center'>Email</th>
<th class='text-center'>Type</th>
<th class='text-center'>Modify</th>
<th class='text-center'>Delete</th>
</tr>";
while ($row = mysqli_fetch_array($rs)) {
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['type'] . "</td>";
echo "<td><input type='submit' value='Modify' class='btn' name='modify'></td>";
echo "<td><input type='submit' value='Delete' class='btn' name='delete'></td>";
echo "</tr>";
}
echo "</table>";
if (isset($_POST['modify'])) {
$username = $row['username'];
$modify_query = mysqli_query($link, "UPDATE benutzer SET type='Mitarbeiter, Chef' WHERE username=$username");
if ($modify_query) {
mysqli_close($link);
header("location:welcome.php");
exit;
} else {
echo mysqli_close($link);
}
}
if (isset($_POST['delete'])) {
$username = $row['username'];
$delete_query = mysqli_query($link, "DELETE FROM benutzer WHERE id=$username");
if ($delete_query) {
mysqli_close($link);
echo "Record deleted successfully";
exit;
} else {
echo mysqli_close($link);
}
}
?>
Try this you were missing hidden input types so the php can't see your code you submitted.
Since you are showing alot of username's you will need to create a bunch of input hidden types with name=username1, name=username2 etc.. or it won't work well I can show you a easier way to do it (look below this code)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pannel</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<style type="text/css">
body {
font: 14px sans-serif;
text-align: center;
}
</style>
</head>
<body>
<div class="page-header">
<h1> Admin Pannel</h1>
</div>
<div>
</div>
</body>
</html>
<?php
session_start();
require('config.php');
$strSQL = "SELECT username, email, type FROM benutzer";
$rs = mysqli_query($link, $strSQL);
echo "<table border='1' style='margin: 0 auto'>
<tr>
<th class='text-center'>Name / Vorname</th>
<th class='text-center'>Email</th>
<th class='text-center'>Type</th>
<th class='text-center'>Modify</th>
<th class='text-center'>Delete</th>
</tr>";
while ($row = mysqli_fetch_array($rs)) {
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['type'] . "</td>";
echo "<form action='pannel.php' method='post'>";
echo "<input type='hidden' id=username' name='username' value='".$row['username']."'>";
echo "<input type='hidden' id=email' name='email' value='".$row['email']."'>";
echo "<input type='hidden' id=type' name='type' value='".$row['type']."'>";
echo "<td><input type='submit' value='Modify' class='btn' name='modify'></td>";
echo "<td><input type='submit' value='Delete' class='btn' name='delete'></td>";
echo "</form>";
echo "</tr>";
}
echo "</table>";
if (isset($_POST['modify'])) {
$username = $_POST['username'];
$modify_query = mysqli_query($link, "UPDATE benutzer SET type='Mitarbeiter, Chef' WHERE username=$username");
if ($modify_query) {
mysqli_close($link);
header("location:welcome.php");
exit;
} else {
echo mysqli_close($link);
}
} else if (isset($_POST['delete'])) {
$username = $_POST['username'];
$delete_query = mysqli_query($link, "DELETE FROM benutzer WHERE username=$username");
if ($delete_query) {
mysqli_close($link);
echo "Record deleted successfully";
exit;
} else {
echo mysqli_close($link);
}
}
EDIT:
Easier way to do it
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pannel</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<style type="text/css">
body {
font: 14px sans-serif;
text-align: center;
}
</style>
</head>
<body>
<div class="page-header">
<h1> Admin Pannel</h1>
</div>
<div>
</div>
</body>
</html>
<?php
session_start();
require('config.php');
$strSQL = "SELECT username, email, type FROM benutzer";
$rs = mysqli_query($link, $strSQL);
echo "<table border='1' style='margin: 0 auto'>
<tr>
<th class='text-center'>Name / Vorname</th>
<th class='text-center'>Email</th>
<th class='text-center'>Type</th>
<th class='text-center'>Modify</th>
<th class='text-center'>Delete</th>
</tr>";
while ($row = mysqli_fetch_array($rs)) {
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['type'] . "</td>";
echo "<td><a href='pannel.php?delete=".$row['username']."'>Delete ".$row['username']."</a></td>";
echo "<td><a href='pannel.php?modify=".$row['username']."'>Modify ".$row['username']."</a></td>";
echo "</tr>";
}
echo "</table>";
if (isset($_GET['modify'])) {
$username = $_GET['modify'];
$modify_query = mysqli_query($link, "UPDATE benutzer SET type='Mitarbeiter, Chef' WHERE username=$username");
if ($modify_query) {
mysqli_close($link);
header("location:welcome.php");
exit;
} else {
echo mysqli_close($link);
}
} else if (isset($_GET['delete'])) {
$username = $_GET['delete'];
$delete_query = mysqli_query($link, "DELETE FROM benutzer WHERE username=$username");
if ($delete_query) {
mysqli_close($link);
echo "Record deleted successfully";
exit;
} else {
echo mysqli_close($link);
}
}
The code below is my way on how to print my data in Table.
<style media="screen">
.noPrint{ display: block; }
.yesPrint{ display: block !important; }
</style>
<style media="print">
.noPrint{ display: none; }
.yesPrint{ display: block !important; }
</style>
Here is my code of printing the data from the table
<div style = "border:1px solid; height:360px; width:1180px; left: 180px; position: absolute; top: 95px; overflow-x: auto;">
<div class="CSSTableGenerator" >
<div class= "yesPrint">
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("dbreport",$con);
$sql = "select * from tblreport";
$mydata = mysql_query($sql,$con);
echo "<table border=1 id='tbody'>
<tr>
<th>Crime Name</th>
<th>Time</th>
<th>Date</th>
<th>Address</th>
<th>Detail</th>
</tr>";
while ($record = mysql_fetch_array($mydata)){
echo "<tr>";
echo "<td>" . $record['Crime Name'] . "</td>";
echo "<td>" . $record['Time'] . "</td>";
echo "<td>" . $record['Date'] . "</td>";
echo "<td>" . $record['Address'] . "</td>";
echo "<td>" . $record['Detail'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_Close($con);
?>
</div>
</div>
</div>
To initiate the command
<input TYPE="button" value = "Print Report" onClick="window.print()">
Further Explanation: My code here is to print the data from my table and the table has been populated from my database. Data Transfer to Table then Print but what happens is the whole website has been print. It seems that my code Capture the site as Image and this what it print.
What I want to do is print what only on the table, how can achieve it? TY
try this,
you r using mysql_Close($con); but in real mysql_close($con);
<div style = "border:1px solid; height:360px; width:1180px; left: 180px; position: absolute; top: 95px; overflow-x: auto;">
<div class="CSSTableGenerator" >
<div class= "yesPrint">
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("dbreport",$con);
$sql = "select * from tblreport";
$mydata = mysql_query($sql,$con);
echo "<table border=1 id='tbody'>
<tr>
<th>Crime Name</th>
<th>Time</th>
<th>Date</th>
<th>Address</th>
<th>Detail</th>
</tr>";
while ($record = mysql_fetch_array($mydata)){
echo "<tr>";
echo "<td>" . $record['Crime Name'] . "</td>";
echo "<td>" . $record['Time'] . "</td>";
echo "<td>" . $record['Date'] . "</td>";
echo "<td>" . $record['Address'] . "</td>";
echo "<td>" . $record['Detail'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
</div>
</div>
</div>
With the below javascript function, you can print any element by just placing the element in the parentheses.
<input type="button" value="Print Div" onclick="PrintElem('.yesPrint')" />
Here is the entire code:
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script>
<script type="text/javascript">
function PrintElem(elem)
{
Popup($(elem).html());
}
function Popup(data)
{
var mywindow = window.open('', 'my div', 'height=400,width=600');
mywindow.document.write('<html><head><title>my div</title>');
/*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.print();
mywindow.close();
return true;
}
</script>
<div style = "border:1px solid; height:360px; width:1180px; left: 180px; position: absolute; top: 95px; overflow-x: auto;" class="noPrint">
<div class="CSSTableGenerator" >
<div class= "yesPrint">
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("dbreport",$con);
$sql = "select * from tblreport";
$mydata = mysql_query($sql,$con);
?>
<table border=1 id='tbody'>
<tr>
<th>Crime Name</th>
<th>Time</th>
<th>Date</th>
<th>Address</th>
<th>Detail</th>
</tr>
<?php
while ($record = mysql_fetch_array($mydata)){
echo "<tr>";
echo "<td>" . $record['Crime Name'] . "</td>";
echo "<td>" . $record['Time'] . "</td>";
echo "<td>" . $record['Date'] . "</td>";
echo "<td>" . $record['Address'] . "</td>";
echo "<td>" . $record['Detail'] . "</td>";
echo "</tr>";
}
?>
</table>
<?php mysql_close($con); ?>
</div>
</div>
</div>
<input type="button" value="Print Div" onclick="PrintElem('.yesPrint')" />
I have a table that shows me data from a call flow.
I need the Data from this table to be manipulated per row in such a way that all the values of my table, which are being looked up from my DB, (which are now in code) will be translated into a text value. Let me show U and explain:
My Table:
<?php
include_once "Connect2Martijn1.php";
?>
<link rel="stylesheet" href="CSSMartijn1.css">
</link>
<head>
<meta charset="iso-8859-1">
<meta name="description"content="VoizXL ">
<meta name="keywords"content="VoizXL ">
<meta name="author"content="Kenn Lo-A-Tjong">
</meta>
<title>Call Flow</title>
</head>
<fieldset>
<article class="rondehoeken">
<header>
<div class="streep1"></div>
<div class="streep2"></div>
<div class="streep3"></div>
<div class="streep4"></div>
<div class="streep5"></div>
<h1 id="artikel-titel" >Call Flow</h1>
</header>
<div id="artikel-container">
<table class="table 1">
<thead>
<title>Call Flow</title>
<meta charset = "UTF-8" />
<style type = "text/css">
table, td, th {
border: 1px solid black;
}
</style>
</thead>
<tbody>
<?php
$con=mysqli_connect("localhost","root","","voizxl_wachtrij");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Callflow");
echo "<table border='0'>
<tr>
<th>Nummer</th>
<th>Naam</th>
<th>Status</th>
<th>Time</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
echo "<td>" . $row['statusAnswered'] . "</td>";
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Example of (how I want to be) Translating the Data:
<?php
if ($row['statusAnswered'] ="NULL")
{
echo "Not Answered!";
}
else
{
echo "Answered!";
}
?>
What I want to Achieve is for eg. that the value in this table from $row['statusAnswered'] will be displayed in text as "Answered or Not Answered" if the Value of this row in the DB is NULL or Not...
How do I do this?
Right now I can only achieve to have 1 echo under the table saying Answered :S
No Idea how to put it per $row.
while($row = mysqli_fetch_array($result))
{
if (!isset($row['statusAnswered']))
{
$answered = "Not Answered!";
}
else
{
$answered = "Answered!";
}
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
echo "<td>" . $answered . "</td>";
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
if ($row['statusAnswered'] =="NULL"||$row['statusAnswered'] =="Null" || $row['statusAnswered'] =="null" || $row['statusAnswered'] =="")
{
echo "<td>Not Answered!</td>";
}
else
{
echo "<td>Answered!</td>";
}
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "<table border='0'>
<tr>
<th>Nummer</th>
<th>Naam</th>
<th>Status</th>
<th>Time</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
echo "<td>" . ($row['statusAnswered']=='NULL'?'Not Answered!':'Answered!') . "</td>";
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
echo "</table>";
You could use;
$checkstatus = if($row['statusAnswered'] = NULL) { echo "Not Answered!"; } else {echo "Answered!";};
then call that by replacing;
echo "<td>" . $row['statusAnswered'] . "</td>";
with;
echo "<td>{$checkstatus}</td>"
I am creating a phonebook program, where I can register and create my own contact list. After login, the page will be directed to the tabmain page where I can view, add, edit or delete contact, in a multitab form.
Here's the problem: Whenever I click the save button (the button in function displayNew), it should be getting the first name and surname then, look for the database if there is a match. If not, then add it should them. Now, what happens is, after I click the save button, nothing is passed to the variable.
Here is my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Tab-View Sample</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<link rel="stylesheet" type="text/css" href="css_collect/distribution/tab-view.css" />
</head>
<body>
<?php $id = isset($_GET['id']) ? $_GET['id'] : 1; ?>
<?php
include 'conSql.php';
session_start();
$mySession = $_SESSION['user'];
//displays firsname and lastname of the user
$getNames = getNames($mySession);
$gET = explode("^", $getNames);
echo "Hi, "."<b>". $gET[0] ." ". $gET[1] ."</b>"."!";
echo "</br>";
echo "</br>";
?>
<div class="TabView" id="TabView">
<!-- ***** Tabs ************************************************************ -->
<div class="Tabs" style="width: 452px;">
<a <?=($id == 1) ? 'class="Current"' : 'href="sample.php?id=1"';?>>Contact List</a>
<a <?=($id == 2) ? 'class="Current"' : 'href="sample.php?id=2"';?>>Add contact</a>
<a <?=($id == 3) ? 'class="Current"' : 'href="sample.php?id=3"';?>>Edit / Delete</a>
</div>
<!-- ***** Pages *********************************************************** -->
<div class="Pages" style="width: 450px; height: 300px;">
<div class="Page" style="display: <?=($id == 1) ? 'block' : 'none';?>"><div class="Pad"></div>
list of query
</div>
<div class="Page" style="display: <?=($id == 2) ? 'block' : 'none';?>"><div class="Pad"></div>
<Form Name ='' Method ='GET' action = 'tabmenu.php'>
<?php
displayNew();
if(isset($_GET['btnAdd'])){
$fname = $_GET['txtFname'];
$lname = $_GET['txtLname'];
// $s = "SELECT * ";
// $s .="FROM tbl_contactlist ";
// $s .="WHERE fname = '". $_GET['txtFname'] ."' and lname = '". $_GET['txtLname'] ."'";
echo $s;
}
?>
</div>
<div class="Page" style="display: <?=($id == 3) ? 'block' : 'none';?>"><div class="Pad"></div>
<?php
displayEdit();
?>
</div>
</div>
</div>
<script type="text/javascript" src="css_collect/distribution/tab-view.js"></script>
<script type="text/javascript">
tabview_initialize('TabView');
</script>
<?php
function getNames($mySession){
//get the real name of the user (firstname and lastname)
$s = "SELECT * ";
$s .="FROM tbl_users ";
$s .="WHERE username = '". $mySession ."' ";
$rc = mysql_query($s);
$row = mysql_fetch_assoc($rc) or die();
$details = $row["fname"]."^".$row["lname"];
return $details;
}
function displayNew(){
echo "<table border = '0'>";
echo "<tr>";
echo "<td colspan='2'><b>New Contact</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='2'>Please fill up the fields.</td>";
echo "</tr>";
echo "<tr>";
echo "<td>First Name: </td>";
echo "<td><input type='text' name='txtFname' id='txtFname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Last Name: </td>";
echo "<td><input type='text' name='txtLname' id='txtLname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Nick Name: </td>";
echo "<td><input type='text' name='txtNicname' id='txtNicname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Contact Number: </td>";
echo "<td><input type='text' name='txtContactNum' id='txtContactNum'></td>";
echo "</tr>";
echo "<tr>";
echo "<td></td>";
echo "<td><input type='submit' name='btnAdd' id='btnAdd' value='SAVE'></td>";
echo "</tr>";
echo "</table>";
}
function displayEdit(){
echo "<table border = '0'>";
echo "<tr>";
echo "<td colspan='2'><b>Edit / Delete Page</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='2'>You can edit or delete:</td>";
echo "</tr>";
echo "<tr>";
echo "<td>First Name: </td>";
echo "<td><input type='text' name='txtFname' id='txtFname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Last Name: </td>";
echo "<td><input type='text' name='txtLname' id='txtLname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Nick Name: </td>";
echo "<td><input type='text' name='txtNicname' id='txtNicname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Contact Number: </td>";
echo "<td><input type='text' name='txtContactNum' id='txtContactNum'></td>";
echo "</tr>";
echo "<tr>";
echo "<td></td>";
echo "<td><input type='submit' name='btnEdit' id='btnEdit' value='EDIT'>";
echo "<input type='submit' name='btnDelete' id='btnDelete' value='DELETE'></td>";
echo "</tr>";
echo "<tr>";
echo "<td></td>";
echo "<td><input type='submit' name='btnCancel' id='btnCancel' value='Cancel'></td>";
echo "</tr>";
echo "</table>";
}
function testMe(){
echo "<script type='text/javascript'>\n";
echo "alert('T E S T');\n";
echo "</script>";
}
?>
</body>
</html>
It looks like you don't ever close the form tag in the HTML, that might cause the page to not do anything when you click submit