I have a question regarding hiding empty rows in my table.
I want to hide an entire row in the case a field says N/A which means the field is empty.
Example:
In the event that the field is empty or N/A, I want to hide the entire row. I will also welcome javascript solutions.
<tbody style="
white-space: nowrap;
">
<?php
foreach($student_subject_list AS $SSL)
{
$subject_name = $SSL["name"];
if(in_array($subject_name, array_keys($result)))
{
$total_score = 0;
$avg = count($result[$subject_name]);
$test_results = "";
$i = 1;
foreach($result[$subject_name] AS $SN)
{
if($i == 1)
{
$ie = "1<sup>st</sup>";
}
elseif($i == 2)
{
$ie = "<br>2<sup>nd</sup>";
}
elseif($i == 3)
{
$ie = "<br>3<sup>rd</sup>";
}
else
{
$ie = "<br>4<sup>th</sup>";
}
$test_results .= "$ie Test: $SN ";
$total_score += $SN;
$avg_score = $total_score/$avg;
$i++;
}
}
else
{
$total_score = $test_results = "N/A";
}
?>
<tr>
<td style="border: 1px solid black; font-size:11px;width:120px;white-space: nowrap;height:30px;"><?=$subject_name?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?=$test_results?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?=$avg_score?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?=$remark?></td>
</tr>
<?php
}
?>
</tbody>
Could you make the html where you create the row conditional on $test_results NOT being equal to "N/A"? Something like this:
<?php if(!$test_results === "N/A"){ ?>
<tr>
<td> etc etc
<td> etc etc
<td> etc etc
<td> etc etc
</tr>
<?php } ?>
Related
thank you in advance for helping me. I am stuck with this problem. I should put different colors of text per row but I only know alternating 2 colors per row. This should be the output
<?php
$color1 = "#32CD32";
$color2 = "#FF0000";
$color3 = "#5e0087";
$color4 = "#FFA500";
$color5 = "#00008b";
$color = NULL;
echo "<table border =\"1\" style='border-collapse: collapse'>";
for ($row=1; $row <= 5; $row++) {
echo "<tr> \n";
$color == $color1 ? $color = $color2: $color = $color1;
for ($col=1; $col <= 4; $col++) {
$num = $col * $row;
echo "<td style = 'color:$color'> $num </td> \n";
}
echo "</tr>";
}
echo "</table>";
?>
You can create dynamic variables in php by creating the string (like "color1" and then putting $$ before it.
$color1 = "#32CD32";
$color2 = "#FF0000";
$color3 = "#5e0087";
$color4 = "#FFA500";
$color5 = "#00008b";
$color = NULL;
echo "<table border =\"1\" style='border-collapse: collapse'>";
for ($row=1; $row <= 5; $row++) {
echo "<tr> \n";
$color = "color".$row;
$color = $$color;
for ($col=1; $col <= 4; $col++) {
$num = $col * $row;
echo "<td style = 'color:$color'> $num </td> \n";
}
echo "</tr>";
}
Here's another option, put the colors in an array
$colors = ["#32CD32", "#FF0000", "#5e0087", "#FFA500", "#00008b"];
then just access the array with the $row #
$color = $colors[$row -1];
You should avoid using individual variables to store related data. By assigning these colors as elements in an array, you afford yourself the ability to loop over the collection of values without the use of "variable variables" (when your script seems to need variable variables, then it is time to rethink your script).
$colors = [
1 => "#32CD32",
2 => "#FF0000",
3 => "#5E0087",
4 => "#FFA500",
5 => "#00008B"
];
You should avoid writing inline styles as much as possible. In truth, I'd recommend that you completely color your rows of text using pure css. However, I get the impression that this is just an exercise in writing dynamic code.
<style>
table {
border-collapse: collapse;
width: 1%;
}
td {
border: solid 1px black;
padding: 8px;
}
</style>
I find myself paying an increasing amount of attention to generating clean well-tabbed source code (in addition to producing clean rendered html). To assist in satisfying my quest, I'll use template strings with printf() and vsprintf().
Code: (Demo)
<?php
$tr = <<<HTML
<tr style="color: %s;">%s
</tr>
HTML;
$tds = str_repeat("\n " . '<td>%s</td>', 4);
?>
<table>
<?php
foreach ($colors as $key => $color) {
printf(
$tr,
$color,
vsprintf(
$tds,
range($key, $key * 4, $key)
)
);
}
?>
</table>
Unrendered Output:
<table>
<tr style="color: #32CD32;">
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
<tr style="color: #FF0000;">
<td>2</td>
<td>4</td>
<td>6</td>
<td>8</td>
</tr>
<tr style="color: #5E0087;">
<td>3</td>
<td>6</td>
<td>9</td>
<td>12</td>
</tr>
<tr style="color: #FFA500;">
<td>4</td>
<td>8</td>
<td>12</td>
<td>16</td>
</tr>
<tr style="color: #00008B;">
<td>5</td>
<td>10</td>
<td>15</td>
<td>20</td>
</tr>
</table>
Using pure CSS is the more professional technique for styling. Once you move the css to an external stylesheet, your php script will be very short and easy to manage.
Code with the same output: (Demo)
<style>
table {
border-collapse: collapse;
width: 1%;
}
tr:nth-child(1) { color: #32CD32; }
tr:nth-child(2) { color: #FF0000; }
tr:nth-child(3) { color: #5E0087; }
tr:nth-child(4) { color: #FFA500; }
tr:nth-child(5) { color: #00008B; }
td {
border: solid 1px black;
padding: 8px;
}
</style>
<?php
$tr = <<<HTML
<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>
HTML;
?>
<table>
<?php
for ($i = 1; $i <= 5; ++$i) {
vprintf(
$tr,
range($i, $i * 4, $i)
);
}
?>
</table>
I'm trying to make an x and y marking table using PHP. I used array and loops to this task.
Please refer to the sample code and image. I almost spent 2hrs finding some solutions still need help.
Very much appreciated for some ideas.
<?php
$x_arr = array();
$y_arr = array();
$n_arr = array();
$x_arr = [5,5,9,14];
$y_arr = [1,4,3,3];
$n_arr = [1,1,1,1];
$x = 16;
$y = 4;
$gap = 3;
$data = "";
?>
<div style="padding:30px; background:#242424;">
<table style="border:20px solid #660000;" align="center">
<?php
//STRIP
for($i=$y; $i>=1; $i--){
?>
<tr style="background:#fff;">
<?php
for($ii=$x; $ii>=1; $ii--){
//echo "<td style='border:1px solid black;'>x".$ii." : y".$i."</td>";
for($iii=0; $iii<=count($x_arr); $iii++){
if(isset($x_arr[$iii]) && isset($y_arr[$iii])){
$x_tmp = $x_arr[$iii];
$y_tmp = $y_arr[$iii];
if($i==$y_tmp && $ii==$x_tmp){
$data= "<td style='border:1px solid black; width:50px; height:30px; text-align:center;'><span data-feather='circle'></span></td>";
echo $data;
}else{
$data = "";
}
}
}
if($data == ""){
echo "<td style='border:1px solid black;'>x".$ii." : y".$i."</td>";
}
//echo "<td style='border:1px solid black;'>          </td>";
//echo "<td style='border:1px solid black; width:50px; height:30px; text-align:center;'><span data-feather='circle'></span></td>";
if($ii>$gap){
$gap = $gap+$gap;
}
}
?>
</tr>
<?php
}
?>
</table>
</div>
Result Error :
Current Result
Expected Result :
Target Result
Recently, I discovered that the exam scores of students are not displaying anymore in a particular class (PRE-NURSERY).
Going back to the form where results are added, I see that the results have been repopulated and are already stored in the database.
However, they are not been displayed in the view. I wonder what must be wrong.
model
public function getRecentmtGradesRN($id)
{
$this->db->select('*');
$this->db->where('student_id', $id);
return $this->db->get('mtscores_rn')->result();
}
controller
public function view($id)
{
if (!$this->rbac->hasPrivilege('student', 'can_view')) {
access_denied();
}
$data['title'] = 'Student Details';
$student = $this->student_model->get($id);
$gradeList = $this->grade_model->get();
if($class_id == 2 || $class_id == 3) //see here
{
$subjectmtScores = $this->student_model->getRecentmtGradesRN($id);
}
else
{
$subjectmtScores = $this->student_model->getRecentmtGrades($id);
}
$studentSession = $this->student_model->getStudentSession($id);
$timeline = $this->timeline_model->getStudentTimeline($id, $status = '');
$data["timeline_list"] = $timeline;
$student_session_id = $studentSession["student_session_id"];
$student_session = $studentSession["session"];
$data['sch_setting'] = $this->sch_setting_detail;
$data['adm_auto_insert'] = $this->sch_setting_detail->adm_auto_insert;
$current_student_session = $this->student_model->get_studentsession($student['student_session_id']);
$data["session"] = $current_student_session["session"];
$student_due_fee = $this->studentfeemaster_model->getStudentFees($student['student_session_id']);
$student_discount_fee = $this->feediscount_model->getStudentFeesDiscount($student['student_session_id']);
$data['student_discount_fee'] = $student_discount_fee;
$data['student_due_fee'] = $student_due_fee;
$siblings = $this->student_model->getMySiblings($student['parent_id'], $student['id']);
$student_doc = $this->student_model->getstudentdoc($id);
$data['student_doc'] = $student_doc;
$data['student_doc_id'] = $id;
$category_list = $this->category_model->get();
$data['category_list'] = $category_list;
$data['gradeList'] = $gradeList;
$data['subjectmtScores'] = $subjectmtScores; //see here
//var_dump($subjectmtScores); die();
$data['student'] = $student;
$data['siblings'] = $siblings;
$class_section = $this->student_model->getClassSection($student["class_id"]);
$data["class_section"] = $class_section;
$session = $this->setting_model->getCurrentSession();
$studentlistbysection = $this->student_model->getStudentClassSection($student["class_id"], $session);
$data["studentlistbysection"] = $studentlistbysection;
$data['guardian_credential'] = $this->student_model->guardian_credential($student['parent_id']);
$data['reason'] = $this->disable_reason_model->get();
if ($student['is_active'] = 'no') {
$data['reason_data'] = $this->disable_reason_model->get($student['dis_reason']);
}
// //var_dump($data['teacher_comment']);
$this->load->view('layout/header', $data);
$this->load->view('student/studentShow', $data);
$this->load->view('layout/footer', $data);
}
view
<table class="table table-bordered" style="border: 1px solid black;">
<caption class="text-center">ACADEMIC PERFORMANCE</caption>
<thead>
<tr style="border: 1px solid black;">
<th style="border: 1px solid black; font-size:11px;width:120px;text-align:center;">
SUBJECTS
</th>
<th style="border: 1px solid black; font-size:11px;text-align:center;">CLASS
EXPECTATION
</th>
<th style="border: 1px solid black;font-size:11px;text-align:center;">MILESTONE
ACHIEVED
</th>
<th style="border: 1px solid black;font-size:11px;text-align:center;">REMARKS</th>
</tr>
</thead>
<tbody>
<?php $i = 1;
$total = 0;
$count = count($subjectmtScores);
foreach ($subjectmtScores as $value) { ?>
<?php
$mt_tot_score = $value->mt_ca1 + $value->mt_ca2 + $value->mt_ca3 + $value->mt_ca4 + $value->mt_affective + $value->mt_psychomotor + $value->mt_exam;
if ($mt_tot_score >= 80) {
$grade = 'A';
$remark = 'EXCELLENT';
} elseif ($mt_tot_score >= 70 && $mt_tot_score <= 79.99) {
$grade = 'B';
$remark = 'VERY GOOD';
} elseif ($mt_tot_score >= 60 && $mt_tot_score <= 69.99) {
$grade = 'C';
$remark = 'GOOD';
} elseif ($mt_tot_score >= 50 && $mt_tot_score <= 59.99) {
$grade = 'E';
$remark = 'PASS';
} elseif ($mt_tot_score >= 40 && $mt_tot_score <= 49.99) {
$grade = 'F';
$remark = 'FAIR';
} elseif ($mt_tot_score >= 0 && $mt_tot_score<= 39.99) {
$grade = 'FL';
$remark = 'FINAL LETTER GRADE';
}
?>
<?php
$total += $mt_tot_score;
?>
<tr style="border: 1px solid black;">
<td style="border: 1px solid black;font-size:12px;text-align:left;height:30px;"><?php echo $CI->GetSubjectNameWithID($value->subject_id); ?></td>
<td style="border: 1px solid black;font-size:12px;text-align:center;"><?php echo $value->mt_ca1; ?></td>
<td style="border: 1px solid black;font-size:12px;text-align:center;"><?php echo $value->mt_ca2; ?></td>
<td style="border: 1px solid black;font-size:12px;text-align:left;white-space:nowrap;"><?php echo $value->mt_ca3; ?></td>
</tr>
<?php $i++;
} ?>
</tbody style="
white-space: nowrap;
">
</table>
I have a niggling error that no one seems to be able to fix but I'm sure it is very simple and possibly CSS related.
I wish for the first column (that is the usernames) to be frozen/fixed in order for the user to scroll through the other columns (the tests, of which there are many).
This now works, but the positioning of the username is out of synch with the rest of the table.
It looks like this:
and it should look like:
PHP and HTML code:
<?php }elseif(isset($_POST['quiz']) && $_POST['quiz'] == "non" && $err == ""){ ?>
<div class="col-sm-12">
<div class="table-responsive">
<table class="table table-bordered table-striped table-condensed" id="table">
<thead>
<tr>
<td width="3%"></td>
<?php
$all_quizes = mysqli_query($con,"SELECT * FROM quizes ORDER BY FIELD(quiz_level, 'Beginner','Intermediate','Advanced'),quiz_name ASC");
$quizes = array();
while($my_rows = mysqli_fetch_array($all_quizes)){
array_push($quizes,$my_rows);
}
foreach($all_quizes as $record){
?>
<th width="30%"><?php echo $record['quiz_name']; ?></th>
<?php } ?>
</tr>
</thead>
<tbody>
<?php foreach(#$result as $record){?>
<tr>
<td class="headcol"><?php echo $record["username"];?></td>
<?php
$counter=0;
echo " ";
while(mysqli_num_rows($all_quizes) > $counter){
$current_td = mysqli_query($con,"SELECT * FROM quiz_takers WHERE username='".$record["username"]."' AND quiz_id=".$quizes[$counter][0]." ORDER BY marks DESC");
$td = mysqli_fetch_array($current_td);
if($td['percentage'] == null){
echo "<td> ?</td>";
}else{
if(intval($td["percentage"]) >= 0 && intval($td["percentage"]) <= 30){
$color = 'red';
}elseif(intval($td["percentage"]) > 30 && intval($td["percentage"]) <= 70){
$color = '#ffbf00';
}elseif(intval($td["percentage"]) <= 30){
}else{
$color = 'green';
}
echo "<td style='color:".$color."'>".round($td["percentage"],2)."%</td>";
}
$counter++;
}
/*foreach($current_td as $td){
echo $counter." ".$td['username'] . " - ".$quizes[$counter]['3']."<br>";
if($quizes[$counter]['0'] == $td['quiz_id']){
?>
<td><?php echo $td["percentage"];?></td>
<?php } $counter++;}*/ ?>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
The current css is:
<style>
.headcol {
position:absolute;
height:100px;
width: 5em;
left: -10;
overflow-x: scroll;
margin-left: 5em;
padding: 0;
top: 2;
border-top-width: -2px;
/*only relevant for first row*/
margin-top: -90px;
/*compensate for top border*/
}
</style>
Could someone please suggest a solution or fix?
I think the issue coming from the first column of the first heading row, which you defined the width of 3%. This width should equal to the width of .headcol
Something like this
<thead>
<tr>
<td width="5em"></td> //equal to the width of .headcol
Besides, you may need to adjust your CSS of .headcol so it can be aligned better, maybe put left: 0;
I've encountered a problem which i'll try to describe below...
Let's say i've got a button for each table row (table is created by acquiring the data from the database...). the button sends a massive of values via post.
<button value='$e->eventId|$e->eventType|$e->eventDate|$e->eventPrice|$e->eventDescr' name='editValue'>EDIT</button>
I've written a function to explode the values of the massive and fill the inputs on the same page.
if(!empty($_POST['editValue'])) {
$editValue_fill = explode("|", $_POST["editValue"]);
$eventId = $editValue_fill[0];
$eventType = $editValue_fill[1];
$eventDate = $editValue_fill[2];
$eventPrice = $editValue_fill[3];
$eventDescr = $editValue_fill[4];
}
Next comes the function to edit the row in the database.
function editEvent ($id, $type, $date, $price, $descr){
$mysqli = new mysqli($GLOBALS["serverHost"], $GLOBALS["serverUsername"], $GLOBALS['serverPassword'], $GLOBALS['dbName']);
$stmt = $mysqli->prepare("UPDATE events_archive SET eventType='?', eventDate='?', eventPrice='?', eventDescr='?' WHERE id='?'");
$stmt->bind_param("ssdss", $type, $date, $price, $descr, $id);
$stmt->execute();
header("Refresh:0");
if($stmt->execute()){
$eventNotice="Event successfully updated!";
}else{
$eventNotice = "Failed to save...";
}
return $eventNotice;
}
And, of course, the usage of the function which apparently doesnt work. The page just refreshes and nothing happens.
if(empty($eventTypeError)&& empty($eventDateError)&& empty($eventPriceError) && empty($eventDescrError)
&& isset($_POST['eventType']) && isset($_POST['eventDate']) && isset ($_POST['eventPrice']) && isset
($_POST['eventDescr']) && !empty($eventId)){
$eventNotice = editEvent($eventId, cleanInput($eventType), cleanInput($eventDate), cleanInput($eventPrice), cleanInput($eventDescr));
}
So basically, gets values from the row -> fills them into inputs in the same page -> if $eventId is set then updates the row, if not - creates a new row (diff. function)
Could anyone give me a tip or help solving the problem? I've been trying to understand the issue and failed dramatically...
<?php
require ("functions.php");
var_dump($_POST);
//kas on sisseloginud, kui ei ole siis
//suunata login lehele
//kas ?logout on aadressireal
if (isset($_GET['logout'])){
session_destroy();
header("Location: login.php");
}
if (!isset ($_SESSION["userId"])){
header("Location: login.php");
}
$confirm = "";
$eventNotice = "";
$eventTypeError = "";
$eventDateError = '';
$eventPriceError = '';
$eventDescrError = '';
$eventType = '';
$eventDescr = '';
$eventPrice = '';
$eventDate = date("Y-m-d");
if (isset ($_POST["eventType"])){
if (empty($_POST['eventType'])){
$eventTypeError = "Please choose the event type!";
} else {
$eventType = $_POST["eventType"];
}
}
if (isset ($_POST ["eventDate"])){
if (empty ($_POST ["eventDate"])){
$eventDateError = "Please choose the date!";
} else {
$eventDate = $_POST["eventDate"];
}
}
if (isset ($_POST ["eventPrice"])){
if (empty ($_POST ["eventPrice"])){
$eventPriceError = "Please type in the price!";
} else {
$eventPrice = $_POST["eventPrice"];
}
}
if (isset ($_POST ["eventDescr"])){
if (empty ($_POST ["eventDescr"])){
$eventDescrError = "Please type in the description!";
}elseif (strlen($_POST["eventDescr"])< 10) {
$eventDescrError = "Description must be longer than 10 symbols!";
$eventDescr = $_POST['eventDescr'];
}else{
$eventDescr = $_POST['eventDescr'];
}
}
$event = getAllEvents();
if(!empty($_POST['delValue'])) {
delEvent($_POST['delValue']);
}
if(!empty($_POST['editValue'])) {
$editValue_fill = explode("|", $_POST["editValue"]);
$eventId = $editValue_fill[0];
$eventType = $editValue_fill[1];
$eventDate = $editValue_fill[2];
$eventPrice = $editValue_fill[3];
$eventDescr = $editValue_fill[4];
echo ($eventId);
echo ($eventDate);
echo ($eventPrice);
echo ($eventType);
echo ($eventDescr);
}
if(empty($eventTypeError)&& empty($eventDateError)&& empty($eventPriceError) && empty($eventDescrError)
&& isset($_POST['eventType']) && isset($_POST['eventDate']) && isset ($_POST['eventPrice']) && isset
($_POST['eventDescr'])){
if(isset($_POST['editValue'])){
$eventNotice = editEvent($eventId, cleanInput($eventType), cleanInput($eventDate), cleanInput($eventPrice), cleanInput($eventDescr));
}elseif(!isset($_POST['editValue'])){
$eventNotice = newEvent(cleanInput($eventType), cleanInput($eventDate), cleanInput($eventPrice), cleanInput($eventDescr));
}
}
?>
<html>
<style>
#import "styles.css";
ul.tab {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
ul.tab li {float: left;}
ul.tab li a {
display: inline-block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
transition: 0.3s;
font-size: 17px;
}
ul.tab li a:hover {
background-color: #ddd;
}
ul.tab li a:focus, .active {
background-color: #ccc;
}
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
</style>
<body>
<form method ="post">
<table class="table1">
<tr>
<td style="text-align:center"><h1>Data</h1></td>
</tr>
<tr>
<th><h2>Profile</h2></th>
</tr>
<tr>
<td>
<table class="table2">
<tr>
<td colspan="3"">Welcome <?=$_SESSION['email'];?>!</td>
</tr>
<tr>
<td colspan="3" style="text-align:center">Log out</td>
</tr>
</table>
<tr>
<td>
<tr>
<td>
<ul class="tab">
<li>Add/edit</li>
<li>Archive</li>
</ul>
<div id="Add/edit" class="tabcontent">
<input type="hidden" value='eventId'>
<table class="table2">
<tr>
<td>Event type:<span class = 'redtext'>*</span></td>
<td style="text-align:left">
<select name="eventType">
<?php if(empty($eventType)){?>
<option value="" selected>Choose here</option>
<?php } else { ?>
<option value="">Choose here</option>
<?php } ?>
<?php if($eventType == "Planned service"){?>
<option value="Planned service" selected>Planned service</option>
<?php } else { ?>
<option value="Planned service">Planned service</option>
<?php } ?>
<?php if($eventType == "Unplanned service"){?>
<option value="Unplanned service" selected>Unplanned service</option>
<?php } else { ?>
<option value="Unplanned service">Unplanned service</option>
<?php } ?>
<?php if($eventType == "Fuel checks"){?>
<option value="Fuel checks" selected>Fuel checks</option>
<?php } else { ?>
<option value="Fuel checks">Fuel checks</option>
<?php } ?>
<?php if($eventType == "Tuning"){?>
<option value="Tuning" selected>Tuning</option>
<?php } else { ?>
<option value="Tuning">Tuning</option>
<?php } ?>
<?php if($eventType == "Car accident"){?>
<option value="Car accident" selected>Car accident</option>
<?php } else { ?>
<option value="Car accident">Car accident</option>
<?php } ?>
</select>
</td>
</tr>
<tr><td colspan="3" class="redtext" style="text-align:center"><?=$eventTypeError?></td></tr>
<tr>
<td>Date:<span class = 'redtext'>*</span></td>
<td style="text-align:left"><input name="eventDate" type ="date" min="1900-01-01" max = "<?=date('Y-m-d'); ?>" value = "<?=$eventDate?>" placeholder="YYYY-MM-DD"></td>
</tr>
<tr><td colspan="3" class="redtext" style="text-align:center"><?=$eventDateError?></td></tr>
<tr>
<td>Price:<span class = 'redtext'>*</span></td>
<td style="text-align:left"><input type="text" name="eventPrice" placeholder="ex. 15.50" onkeypress="return onlyNumbersWithDot(event);" / value = "<?=$eventPrice?>"></td>
<script type="text/javascript">
function onlyNumbersWithDot(e) {
var charCode;
if (e.keyCode > 0) {
charCode = e.which || e.keyCode;
}
else if (typeof (e.charCode) != "undefined") {
charCode = e.which || e.keyCode;
}
if (charCode == 46)
return true
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
</script>
</tr>
<tr><td colspan="3" class="redtext" style="text-align:center"><?=$eventPriceError?></td></tr>
<tr>
<td>Description:<span class = 'redtext'>*</span></td>
<td style="text-align:left"><textarea name="eventDescr" cols="50" rows="10" placeholder="Describe event here..."><?=$eventDescr?></textarea></td>
</tr>
<tr><td colspan="3" class="redtext" style="text-align:center"><?=$eventDescrError?></td></tr>
<tr>
<td colspan="3" style="text-align:center"><button type ="submit" value = "Submit">Save</button></td>
</tr>
<tr>
<td colspan="3" style="text-align:center"><p class = "redtext"><?=$eventNotice;?></p></td>
</tr>
</table>
</div>
</form>
<form method="post">
<div id="Archive" class="tabcontent">
<table class="table2">
<tr>
<td colspan="3"">
<?php
$html = "<table>";
$html .= "<tr>";
$html .= "<th>Event type</th>";
$html .= "<th>Date</th>";
$html .= "<th>Price(€)</th>";
$html .= "<th>Description</th>";
$html .= "<th>Delete</th>";
$html .= "<th>Edit</th>";
$html .= "</tr>";
foreach($event as $e){
$html .= "<tr>";
$html .= "<td>$e->eventType</td>";
$html .= "<td>$e->eventDate</td>";
$html .= "<td>$e->eventPrice</td>";
$html .= "<td>$e->eventDescr</td>";
$html .= "<td><button style='border:none; background-color: transparent;' value='$e->eventId' name='delValue' onclick=\"return confirm('Do you really want to delete this row?')\"><img src='delete.png' width='20' height='20'></button></td>";
$html .= "<td><button style='border:none; background-color: transparent;' value='$e->eventId|$e->eventType|$e->eventDate|$e->eventPrice|$e->eventDescr' name='editValue'><img src='edit.png' width='20' height='20'></button></td>";
$html .= "</tr>";
}
$html .= "</table>";
echo $html;
?>
</td>
</tr>
</div>
<script>
function openTab(evt, tabName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " active";
}
// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
</script>
</td>
</tr>
</table>
</td>
</tr>
</div>
</form>
</body>
</html>
Looking forward to Your help!
Best regards :)
if(isset($_POST['editValue'])){
$eventNotice = editEvent($eventId, cleanInput($eventType), cleanInput($eventDate), cleanInput($eventPrice), cleanInput($eventDescr));
}