when i refresh will delete all records - php

I have problem the function work without when I click on drop so what is the problem here
I need to delete the record only when I click on the drop so please any help
are the query in function drop correct?
<?php
$sql="SELECT * FROM administrators";
$record=mysql_query($sql);
function drop($id,$email){
$q="DELETE FROM administrators WHERE id='$id' AND email='$email'";
mysql_query($q);
}
?>
<title>Admins Table</title>
<style>
table, th, td {
border: 2px solid black;
border-collapse: collapse;
}
#creating {
font:bold;
font-size:1.6em;
}
</style>
<a href='cadmin.php' id='creating'>Create New Admin</a><br/><br/>
<table width="920" border="1" cellpadding="1" cellspacing="1">
<tr>
<th>Number</th>
<th>First Name</th>
<th>Last Name</th>
<th>Phone Number</th>
<th>Gender</th>
<th>Email</th>
<th>Address</th>
<th>Update</th>
<th>Delete</th>
</tr>
<?php
while($row=mysql_fetch_assoc($record)){
echo'<tr>';
echo'<td>'.$row['id'].'</td>';
echo'<td>'.$row['first_name'].'</td>';
echo'<td>'.$row['last_name'].'</td>';
echo'<td>'.$row['phone'].'</td>';
echo'<td>'.$row['gender'].'</td>';
echo'<td>'.$row['email'].'</td>';
echo'<td>'.$row['address'].'</td>';
echo'<td>'."<a href='' onclick=''>Edit</a>".'</td>';
echo'<td>'."<a href='' onclick='".drop($row['id'],$row['email'])."'> Drop</a>".'</td>';
echo'</tr>';
}
?>
</table>
//code here

try this code
<?php
$sql="SELECT * FROM administrators";
$record=mysql_query($sql);
function drop($id,$email){
$q="DELETE FROM administrators WHERE id='$id' AND email='$email'";
mysql_query($q);
header("Refresh:0");
}
if (isset($_GET['drop'])) {
$id=$_GET['id'];$email=$_GET['email'];
drop($id,$email);
}
?>
<title>Admins Table</title>
<style>
table, th, td {
border: 2px solid black;
border-collapse: collapse;
}
#creating {
font:bold;
font-size:1.6em;
}
</style>
<a href='cadmin.php' id='creating'>Create New Admin</a><br/><br/>
<table width="920" border="1" cellpadding="1" cellspacing="1">
<tr>
<th>Number</th>
<th>First Name</th>
<th>Last Name</th>
<th>Phone Number</th>
<th>Gender</th>
<th>Email</th>
<th>Address</th>
<th>Update</th>
<th>Delete</th>
</tr>
<?php
while($row=mysql_fetch_assoc($record)){
echo'<tr>';
echo'<td>'.$row['id'].'</td>';
echo'<td>'.$row['first_name'].'</td>';
echo'<td>'.$row['last_name'].'</td>';
echo'<td>'.$row['phone'].'</td>';
echo'<td>'.$row['gender'].'</td>';
echo'<td>'.$row['email'].'</td>';
echo'<td>'.$row['address'].'</td>';
echo'<td>'."<a href='' onclick=''>Edit</a>".'</td>';
echo'<td>'."<a href='? drop=ss&id=".$row['id'].'&email='.$row['email']."'> Drop</a>".'</td>';
echo'</tr>';
}
?>

Related

I want to change the php row text based on the value from the database with php

<table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap" style="border-collapse: collapse; border-spacing: 0; width: 100%;">
<thead>
<tr>
<th>SL</th>
<th>Name</th>
<th>Department</th>
<th>Course</th>
<th>Unit</th>
<th>Contact No</th>
<th>Address</th>
<th>Picture</th>
<th>Date/Time</th>
</tr>
</thead>
<tbody>
<?php
$query=mysqli_query($db_con,'SELECT * FROM `student_info` ORDER BY `student_info`.`datetime` DESC;');
$i=1;
while ($result = mysqli_fetch_array($query)) { ?>
<tr>
<?php
echo '<td>'.$i.'</td>
<td>'.ucwords($result['name']).'</td>
<td>'.ucwords($result['department']).'</td>
<td>'.ucwords($result['course']).'</td>
<td>'.ucwords($result['unit']).'</td>
<td>'.ucwords($result['pcontact']).'</td>
<td>'.ucwords($result['address']).'</td>
<td>'.ucwords($result['datetime']).'</td>
<td><img class="rounded-circle avatar-xl" src="images/'.$result['photo'].'" ></td>';?>
</tr>
<?php $i++;} ?>
</tbody>
</table>
All i want to achieve is when department is Computer color should be blue, when is Agric, color should be green, when is Kinetic color should be red etc.
Make a function, which returns a CSS class string
function departmentColor($value) {
$value = strtolower($value);
if ($value === 'computer') return 'bg-blue';
if ($value === 'agric') return 'bg-green';
if ($value === 'kinetic') return 'bg-red';
return '';
}
Make the classes
.bg-blue{background-color:blue}
.bg-green{background-color:green}
.bg-red{background-color:red}
Call the function
<td class="<?= departmentColor($result['department']) ?>">
Or, make a map of classes/colors
$departmentColor = [
'computer' => 'blue',
'agric' => 'green',
'kinetic' => 'red'
];
Then use on the table row (is bit messy)
<td style="<?= array_key_exists(strtolower($result['department']), $departmentColor) ? 'background-color:'.$departmentColor[strtolower($result['department'])] : '' ?>">
If you want the whole row highlighted, then place in tr, not the td.

How can i create vertical side heading table in tcpdf

when i use this method, the heading of table is horizontal, not the vertical heading.
$link= mysqli_connect($host, $user, $pass, $db);
if (isset($_GET['eid']))
{
$eid=$_GET['eid'];
}
$output = '';
$count=0;
$sql = "SELECT * FROM event_record where eventID='{$eid}' ";
$result = mysqli_query($link, $sql);
while($row = mysqli_fetch_array($result))
{
$count++;
$output .= "<tr>
<td>$count</td>
<td>{$row['studentID']}</td>
<td>{$row['studentName']}</td>
<td>{$row['contact']}</td>
<td>{$row['program']}</td>
<td>{$row['booking_date']}</td>
<td>{$row['booking_type']}</td>
</tr>
";
}
return $output;
i want the result of the pdf is , the table heading is at the vertical and at the left side, not horizontal.
<table class="table table-bordered">
<tr>
<th width="3%">No.</th>
<th width="10%">Student ID</th>
<th width="10%">Student Name</th>
<th width="10%">Contact</th>
<th width="5%">Program</th>
<th width="8%">Booking Date</th>
<th width="10%">Booking Type</th>
</tr>
<?php
echo fetch_data();
?>
</table>
Below code is merge the value and the table heading
<table border="1" cellspacing="0" cellpadding="3">
<tr>
<th width="5%">No.</th>
<th width="15%">Student ID</th>
<th width="20%">Student Name</th>
<th width="15%">Contact</th>
<th width="10%">Program</th>
<th width="15%">Booking Date</th>
<th width="15%">Booking Type</th>
</tr>
';
$content .= fetch_data();
$content .= '</table>';
$obj_pdf->writeHTML($content);
$obj_pdf->Output('file.pdf', 'I');
I need a result like this,

What's going wrong with my code

I am targeting a table in the database where the data is stored using serialize() function. So I am trying to unserialize the data & fetching in order to display in the HTML Table. The first row in the table, i.e, table data () is somehow displaying properly. But, the next data (coming through looping ) will be showing on the same line instead of next . Please help me out with this. Also if I am wrong in my explanation, please edit it. Here is my code...
<body style="font-family: verdana; letter-spacing: 2px">
<br><br>
<style>
table, td, th {
border: 1px solid #ddd;
text-align: left;
font-size: 14px;
}
table {
border-collapse: collapse;
width: 90%;
margin: 0 auto;
}
th, td {
padding: 10px;
}
</style>
<table style="border-collapse: collapse; margin: 0 auto" cellpadding="13" border="1" width="80%">
<tr>
<th>Status</th>
<th>Company Name</th>
<th>Address</th>
<th>Your Name</th>
<th>Email</th>
<th>Phone</th>
<th>Website</th>
<th>Software Link</th>
</tr>
<tr>
<?php
$con = mysqli_connect("localhost", "ghgh", "1223546", "rererer");
$que = "SELECT * FROM wp_db7_forms WHERE form_post_id = 6167";
$run = mysqli_query($con, $que);
while ($row = mysqli_fetch_array($run)) {
$form_value = $row['2'];
$form_date = $row['3'];
$array = unserialize($form_value);
$expire = date("Y-m-d", strtotime("+90 days"));
while (list($key, $value) = each($array)) {
?>
<td style="text-align: center;"><?php echo $value; ?></td>
<?php
}
}
?>
</tr>
</table>
</body
You are managing the tr tags wrongly. You really put all dynamic content in one row, since you only generate one opening and one closing tr tag for it -- outside of all loops you have.
So put them inside the outer loop:
<table style="border-collapse: collapse; margin: 0 auto" cellpadding="13" border="1" width="80%">
<tr>
<th>Status</th>
<th>Company Name</th>
<th>Address</th>
<th>Your Name</th>
<th>Email</th>
<th>Phone</th>
<th>Website</th>
<th>Software Link</th>
</tr>
<?php
$con = mysqli_connect("localhost", "ghgh", "1223546", "rererer");
$que = "SELECT * FROM wp_db7_forms WHERE form_post_id = 6167";
$run = mysqli_query($con, $que);
while ($row = mysqli_fetch_array($run))
{ ?>
<tr>
<?php
$form_value = $row['2'];
$form_date = $row['3'];
$array = unserialize($form_value);
$expire = date("Y-m-d", strtotime("+90 days"));
while (list($key, $value) = each($array)) {
?>
<td style="text-align: center;"><?php echo $value; ?></td>
<?php } ?>
</tr>
<?php } ?>
</table>
as #trincot said, you are managing the tr tags wrong, here's a cleaner version of the code separating the php and HTML to keep your code clean and more readable :
<?php
$connection = mysqli_connect('','','','');
$result = mysqli_query($connection,'SELECT .... ');
$rows = [];
while($row = mysqli_fetch_array($result))
{
$rows[] = [
'value' => $row['2'],
'date' => $row['3'],
'expire' => date("Y-m-d", strtotime("+90 days")),
'data' => unserialize($row['2'])
];
}
?>
<table style="border-collapse: collapse; margin: 0 auto" cellpadding="13" border="1" width="80%">
<tr>
<th>Status</th>
<th>Company Name</th>
<th>Address</th>
<th>Your Name</th>
<th>Email</th>
<th>Phone</th>
<th>Website</th>
<th>Software Link</th>
</tr>
<?php foreach($rows as $row) : ?>
<tr>
<?php foreach ($row['data'] as $key => $value) : ?>
<td style="text-align: center;"><?= $value; ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>

Html, Vue, Laravel - loop in v-for and table

I hava a simple table, every tr is a link with a sepcific order, but I have to have one extra column n th with checking or this order is already in store. ( with checboxes ) I can't to this because when I add this, then all row i a link, but I want to this last column wasn't a link, but simple checboxes.
Here is my code:
<table class="table">
<tr>
<th>Order Number</th>
<th>Name</th>
<th>Tel</th>
<th>Email</th>
<th>Status</th>
<th>Order date</th>
<th>IS in store?</th>
</tr>
<router-link :to="'/orderDetail/'+order.id" tag="tr" v-for="order in orders" :key="order.number"
class="order-row">
<td>{{order.number}}</td>
<td>{{order.client_name}}</td>
<td>{{order.phone}}</td>
<td>{{order.email}}</td>
<td>{{order.actual_status}}</td>
<td>{{order.order_date}}</td>
<td>Here should be checbox with id of roder, but not as a link</td>
</router-link>
</table>
html css :
.order-row:hover td {
cursor: pointer;
transition-duration: 0.3s;
background-color: #EfEEEE;
border-top: 1px solid #e0093e;
border-bottom: 1px solid #e0093e;
color: #e0093e;
}
First create one method, something like this
orderRedirect: function(order) {
this.$router.replace('/orderDetail/' + order.id); // For Vuejs 2
this.$route.router.go('/orderDetail/' + order.id); //For Vuejs 1
},
Then call this function on click from table td, something like this
<table class="table">
<tr>
<th>Order Number</th>
<th>Name</th>
<th>Tel</th>
<th>Email</th>
<th>Status</th>
<th>Order date</th>
<th>IS in store?</th>
</tr>
<tr v-for="order in orders" class="order-row">
<td #click="orderRedirect(order)" style="cursor: pointer">{{order.number}}</td>
<td #click="orderRedirect(order)" style="cursor: pointer">{{order.client_name}}</td>
<td #click="orderRedirect(order)" style="cursor: pointer">{{order.phone}}</td>
<td #click="orderRedirect(order)" style="cursor: pointer">{{order.email}}</td>
<td #click="orderRedirect(order)" style="cursor: pointer">{{order.actual_status}}</td>
<td #click="orderRedirect(order)" style="cursor: pointer">{{order.order_date}}</td>
<td><input type="checkbox"></td>
</tr>
</table>
This is one of way that you can remove link from checkbox td
Try something along the lines of:
<td><input type="checkbox" v-model="order.actual_status"></td>

How to fix table with unbalanced thead and tbody

I created a table with fix table head. I use this simple CSS to do that.
.table-fixed thead {
width: 97%;
}
.table-fixed tbody {
width: 97%;
height: 340px;
display:block;
overflow:auto;
}
but the n the output will come like this;
I call the table from ajax. so here is the table code;
echo "<table class=\"table table-bordered table-fixed\">
<thead>
<tr>
<th class=\"col-xs-1\">No</th>
<th class=\"col-xs-2\">Name of Student</th>
<th class=\"col-xs-1\">Nic No</th>
<th class=\"col-xs-1\">Reg. No.</th>
<th class=\"col-xs-1\">adm. date</th>
<th class=\"col-xs-1\">room No</th>
<th class=\"col-xs-3\">Address</th>
<th class=\"col-xs-2\">Contact No.</th>
</tr>
</thead>
<tbody>";
$count = 1;
while($row = $result->fetch_assoc()) {
echo"
<tr id=\"".$row["reg_no"]."\" onclick=\"Redirect(this.id)\">
<td class=\"col-xs-1\">".$count."</td>
<td class=\"col-xs-2\">".$row["name_initial"]."</td>
<td class=\"col-xs-1\">".$row["nic"]."</td>
<td class=\"col-xs-1\">".$row["reg_no"]."</td>
<td class=\"col-xs-1\"></td>
<td class=\"col-xs-1\"></td>
<td class=\"col-xs-3\">".$row["resedential_adress"]."</td>
<td class=\"col-xs-2\">".$row["contact_no"]."</td></tr>
";
$count++;
}
echo "
</tbody></table>";
}
please Help me to fix this problem.
Remove display:block; from table-fixed tbody {} It will override default table property
.table-fixed thead {
width: 97%;
}
.table-fixed tbody {
width: 97%;
height: 340px;
overflow:auto;
}
issue is in your css
remove display:block; and try

Categories