Results are not displaying in view - php

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>

Related

Upload uploading dark photo

I have a system for registering products, where the part of including photos is like this:
The code that on the part of the photos is like this:
$visualizar = '<table class="table table-bordered">
<tr>
<td style="text-align: center; background-color: #367FA9; color: #FFF; font-weight: bold">Tamanho <i class="fa fa-plus-circle" aria-hidden="true"></i></td>
<td style="text-align: center; background-color: #367FA9; color: #FFF; font-weight: bold">Quantidade</td>
<td style="text-align: center; background-color: #367FA9; color: #FFF; font-weight: bold">EAN</td>
</tr>';
$sql = mysqli_query($this->conexao,"SELECT * FROM loja_tamanho_grades WHERE IdGrades = '".$grades."';");
///$c = 0;
while($isfast = mysqli_fetch_assoc($sql))
{
$sqlTamanhos = mysqli_query($this->conexao,"SELECT * FROM loja_tamanhos WHERE IdTamanhos = '".$isfast["IdTamanhos"]."';");
$isfastTamanhos = mysqli_fetch_assoc($sqlTamanhos);
$visualizar .= '<tr>
<td style="font-weight: bold; text-align: center; font-size: 20px; font-style:Arial">
<input type="hidden" name="GradesEscolhidas[]" value="'.$grades.'">
<input type="text" name="TamanhosEscolhidos[]" style="border: 0px; width: 50px; text-align: center" readonly value="'.$isfastTamanhos["Tamanhos"].'">
</td>
<td>
<input type="number" name="QtdEscolhidos[]" class="form-control" min="0" oninput="this.value = Math.abs(this.value)" value="0">
</td>
<td>
<input type="text" name="EANEscolhidos[]" class="form-control" maxlength="17" style="width: 100%">
</td>
</tr>';
}
$visualizar .= '<tr>
<td colspan="3" class="text-left">
<label for="fotos" class="upload">Selecionar fotos <i class="fa fa-plus-circle fa-lg" aria-hidden="true"></i></label>
<input type="hidden" name="GradesFotos[]" value="'.$grades.'">
<input id="fotos" type="file" name="Fotos[]['.$grades.']" multiple>
</td>
</tr>';
//$c++;
$visualiza[] = $visualizar;
echo json_encode($visualiza);
When the user clicks sign up, it is directed to the method below:
if($_POST["Submit"] == "Cadastrar"){
$fotos = $_FILES["Fotos"];
$fotosTemp = $_FILES["Fotos"]["tmp_name"];
$dados = array_filter($_POST);
echo $metodos->cadastrarProdutos($dados,$fotos,$fotosTemp);
}
And the method cadastrarProdutos():
public function cadastrarProdutos(array $dados,$fotos,$fotosTemp)
{
...
$gradesEscolhidas = $dados["GradesEscolhidas"];
for($f = 0; $f < count($fotos['name']); $f++)
{
foreach($fotos['name'][$f] as $key => $value){
$fotosProd = $value;
$tempProd = $fotos['tmp_name'][$f];
$extensoesProd = array('png', 'jpg', 'jpeg','JPG');
$validarProd = pathinfo($fotosProd, PATHINFO_EXTENSION);
list($nomeFotoProd, $extensaoFotoProd) = explode($validarProd, $fotosProd);
$data = date("Y-m-d H:i");
$nomeFotoProd = md5($nomeFotoProd).".".$validarProd;
if($fotosProd == $fotoPrincipal[0])
{
$nomeFotoPrinc = $nomeFotoProd;
}
if(!in_array(strtolower($validarProd), $extensoesProd))
{
$_SESSION["ErroFoto"] = "Extensões permitidas: png e jpg";
$_SESSION["Erro"] = time() + 2;
}
else
{
move_uploaded_file($tempProd, '../../site/produtos/'.$nomeFotoProd);
$diretorioNormal = "../../site/produtos/";
$fotoDir = $diretorioNormal.$nomeFotoProd;
list($largura, $altura) = getimagesize($fotoDir);
if($validarProd == 'jpg' || $validarProd == 'jpeg' || $validarProd == 'JPG')
{
$imagem = imagecreatefromjpeg($fotoDir);
$x = 502;
$y = 529;
$origem_x = imagesx($imagem);
$origem_y = imagesy($imagem);
if($origem_x > $origem_y)
{
$final_x = $x;
$final_y = floor($x * $origem_y / $origem_x);
$f_x = 0;
$f_y = round(($y / 2) - ($final_y / 2));
}
else
{
$final_x = floor($y * $origem_x / $origem_y);
$final_y = $y;
$f_x = round(($x / 2) - ($final_x / 2));
$f_y = 0;
}
$miniatura = imagecreatetruecolor($x, $y);
imagecopyresampled($miniatura, $imagem, 0, 0, 0, 0, $x, $y, $largura, $altura);
imagejpeg($miniatura,$fotoDir,9);
}
if($validarProd == 'png')
{
$imagem = imagecreatefrompng($fotoDir);
$x = 502;
$y = 529;
$origem_x = imagesx($imagem);
$origem_y = imagesy($imagem);
if($origem_x > $origem_y)
{
$final_x = $x;
$final_y = floor($x * $origem_y / $origem_x);
$f_x = 0;
$f_y = round(($y / 2) - ($final_y / 2));
}
else
{
$final_x = floor($y * $origem_x / $origem_y);
$final_y = $y;
$f_x = round(($x / 2) - ($final_x / 2));
$f_y = 0;
}
$miniatura = imagecreatetruecolor($x, $y);
imagecopyresampled($miniatura, $imagem, 0, 0, 0, 0, $x, $y, $largura, $altura);
imagepng($miniatura,$fotoDir,9);
}
$query = "INSERT INTO loja_fotos_produtos(IdProdutos,IdGrades,Fotos) VALUES(?,?,?);";
$stmt = mysqli_prepare($this->conexao,$query);
mysqli_stmt_bind_param($stmt,"sss",$idProduto,$key,$value);
mysqli_stmt_execute($stmt);
if(mysqli_affected_rows($this->conexao) > 0)
{
$_SESSION["Sucesso"] = time() + 5;
}
}
}
}
}
Registration usually occurs, but the photos are as follows. How can I fix this?

X & Y Marking Table Using Php

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;'>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</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

Hide row if field is N/A or empty

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 } ?>

Truncate before inserting data to mysql with PHP

I'm trying to upload an excel file to a mysql DB using PHP. I've got this working.
However, if I refresh the page or upload again another file, it gets duplicated.
I would like before it uploads a new file to clear (truncate) the table and then insert the new data.
Bue I cannot find where to put or how to put the TRUNCATE TABLE existencias_2018; if the Submit button is clicked and before it inserts the data.
Another issue is the refreshing thing. It is a way to stop the refresh after I've uploaded the data? Or a way that refreshing doesn't duplicate it?
So in summary the help i need is:
Where to put and how the TRUNCATE TABLE existencias_2018;.
Stop duplicating data if page gets refreshed.
Here is my piece of code:
<?php
$conn = mysqli_connect("localhost","root","","papa");
require_once('vendor/php-excel-reader/excel_reader2.php');
require_once('vendor/SpreadsheetReader.php');
if (isset($_POST["import"])){
$allowedFileType = ['application/vnd.ms-excel','text/xls','text/xlsx','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
if(in_array($_FILES["file"]["type"],$allowedFileType)){
$targetPath = 'uploads/'.$_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $targetPath);
$Reader = new SpreadsheetReader($targetPath);
$sheetCount = count($Reader->sheets());
for($i=0;$i<$sheetCount;$i++){
$Reader->ChangeSheet($i);
foreach ($Reader as $Row){
$model = "";
if(isset($Row[0])) {
$model = mysqli_real_escape_string($conn,$Row[0]);
}
$cup = "";
if(isset($Row[1])) {
$cup = mysqli_real_escape_string($conn,$Row[1]);
}
$color = "";
if(isset($Row[1])) {
$color = mysqli_real_escape_string($conn,$Row[2]);
}
$description = "";
if(isset($Row[1])) {
$description = mysqli_real_escape_string($conn,$Row[3]);
}
$size36 = "";
if(isset($Row[1])) {
$size36 = mysqli_real_escape_string($conn,$Row[4]);
}
$size38 = "";
if(isset($Row[1])) {
$size38 = mysqli_real_escape_string($conn,$Row[5]);
}
$size40 = "";
if(isset($Row[1])) {
$size40 = mysqli_real_escape_string($conn,$Row[6]);
}
$size42 = "";
if(isset($Row[1])) {
$size42 = mysqli_real_escape_string($conn,$Row[7]);
}
$size44 = "";
if(isset($Row[1])) {
$size44 = mysqli_real_escape_string($conn,$Row[8]);
}
$size46 = "";
if(isset($Row[1])) {
$size46 = mysqli_real_escape_string($conn,$Row[9]);
}
$size48 = "";
if(isset($Row[1])) {
$size48 = mysqli_real_escape_string($conn,$Row[10]);
}
$size50 = "";
if(isset($Row[1])) {
$size50 = mysqli_real_escape_string($conn,$Row[11]);
}
$size52 = "";
if(isset($Row[1])) {
$size52 = mysqli_real_escape_string($conn,$Row[12]);
}
$size54 = "";
if(isset($Row[1])) {
$size54 = mysqli_real_escape_string($conn,$Row[13]);
}
if (!empty($model) || !empty($cup) || !empty($color) || !empty($description) || !empty($size36) || !empty($size38) || !empty($size40) || !empty($size42) || !empty($size44) || !empty($size46) || !empty($size48) || !empty($size50) || !empty($size52) || !empty($size54)) {
$query = "insert into existencias_2018(model,cup,color,description,size36,size38,size40,size42,size44,size46,size48,size50,size52,size54) values('".$model."','".$cup."','".$color."','".$description."','".$size36."','".$size38."','".$size40."','".$size42."','".$size44."','".$size46."','".$size48."','".$size50."','".$size52."','".$size54."')";
$result = mysqli_query($conn, $query);
if (! empty($result)) {
$type = "success";
$message = "Datos de Excel importados en la base de datos satisfactoriamente";
} else {
$type = "error";
$message = "Ha habido un problema al importar los datos de Excel";
}
}
}
}
}else{
$type = "error";
$message = "Tipo de archivo invalido. Suba un archivo de Excel.";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Arial;
width: 1000px;
}
.outer-container {
background: #F0F0F0;
border: #e0dfdf 1px solid;
padding: 40px 20px;
border-radius: 2px;
}
.btn-submit {
background: #333;
border: #1d1d1d 1px solid;
border-radius: 2px;
color: #f0f0f0;
cursor: pointer;
padding: 5px 20px;
font-size:0.9em;
}
.tutorial-table {
margin-top: 40px;
font-size: 0.8em;
border-collapse: collapse;
width: 100%;
}
.tutorial-table th {
background: #f0f0f0;
border-bottom: 1px solid #dddddd;
padding: 8px;
text-align: left;
}
.tutorial-table td {
background: #FFF;
border-bottom: 1px solid #dddddd;
padding: 8px;
text-align: left;
}
#response {
padding: 10px;
margin-top: 10px;
border-radius: 2px;
display:none;
}
.success {
background: #c7efd9;
border: #bbe2cd 1px solid;
}
.error {
background: #fbcfcf;
border: #f3c6c7 1px solid;
}
div#response.display-block {
display: block;
}
</style>
</head>
<body>
<h2>Importar existencias actualizadas</h2>
<div class="outer-container">
<form action="" method="post"
name="frmExcelImport" id="frmExcelImport" enctype="multipart/form-data">
<div>
<label>Buscar archivo Excel</label>
<input type="file" name="file" id="file" accept=".xls,.xlsx">
<button type="submit" id="submit" name="import" class="btn-submit">Importar</button>
</div>
</form>
</div>
<div id="response" class="<?php if(!empty($type)) { echo $type . " display-block"; } ?>"><?php if(!empty($message)) { echo $message; } ?></div>
<?php
$sqlSelect = "SELECT * FROM existencias_2018";
$result = mysqli_query($conn, $sqlSelect);
if (mysqli_num_rows($result) > 0){
?>
<table class='tutorial-table'>
<thead>
<tr>
<th>Modelo</th>
<th>Copa</th>
<th>Color</th>
<th>Descripcion</th>
<th>36</th>
<th>38</th>
<th>40</th>
<th>42</th>
<th>44</th>
<th>46</th>
<th>48</th>
<th>50</th>
<th>52</th>
<th>54</th>
</tr>
</thead>
<?php
$sql = "TRUNCATE TABLE existencias_2018";
while ($row = mysqli_fetch_array($result)) {
?>
<tbody>
<tr>
<td><?php echo $row['model']; ?></td>
<td><?php echo $row['cup']; ?></td>
<td><?php echo $row['color']; ?></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['size36']; ?></td>
<td><?php echo $row['size38']; ?></td>
<td><?php echo $row['size40']; ?></td>
<td><?php echo $row['size42']; ?></td>
<td><?php echo $row['size44']; ?></td>
<td><?php echo $row['size46']; ?></td>
<td><?php echo $row['size48']; ?></td>
<td><?php echo $row['size50']; ?></td>
<td><?php echo $row['size52']; ?></td>
<td><?php echo $row['size54']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
}
?>
</body>
</html>
Is that what you want ?
<?php
$conn = mysqli_connect("localhost","root","","papa");
require_once('vendor/php-excel-reader/excel_reader2.php');
require_once('vendor/SpreadsheetReader.php');
if (isset($_POST["import"])){
$allowedFileType = ['application/vnd.ms-excel','text/xls','text/xlsx','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
if(in_array($_FILES["file"]["type"],$allowedFileType)){
// Looks like we have a correct file to upload.
// Let's TRUNCATE the table first :
$query = "TRUNCATE TABLE existencias_2018;";
mysqli_query($conn, $query);
// OK, table is empty, proceed with upload....
$targetPath = 'uploads/'.$_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $targetPath);
$Reader = new SpreadsheetReader($targetPath);
$sheetCount = count($Reader->sheets());
for($i=0;$i<$sheetCount;$i++){
$Reader->ChangeSheet($i);
foreach ($Reader as $Row){
$model = "";
if(isset($Row[0])) {
$model = mysqli_real_escape_string($conn,$Row[0]);
}
// and so on...

run php code if $players is between 5 and 9 in third span

Ok i edit my question i think i understand more now how to build a question.
The website: bit DOT ly/1MHItEH
I want to run a php code when span 3 is between 5 & 9.
The code which outputs this is $players and in the bottom there is a html output code
<td><span style='text-shadow: 0 0 10px #ffca00; color: #ffca00; font-size: 20pt;'>". $players ."</span></td>
This php code outputs a html table with different values for every added server.
For example if i add a new server to servers.php it will create a new span for that server with new values. So basicly it reads and outputs different values for every server.
So how can i just run extra php code if the span 3 is between 5 & 9?
<html>
<head>
<meta charset="utf-8">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style>
tr td, tr th { text-align: center !important; }
tr td.motd, tr th.motd { text-align: left !important; }
</style>
</head>
<body style="width: 100%; margin: 0 auto; height: 20px; ">
<table class='table table-bordered table-striped'>
</br>
<?php
error_reporting(0);
function openserveriai() {
}
function closeserveriai() {
}
function getnextstring(&$data) {
$temp="";
$counter=0;
while (ord($data[$counter++])!=0) $temp.=$data[$counter-1];
$data=substr($data,strlen($temp)+1);
return $temp;
}
function getnextbytevalue(&$data) {
$temp=ord($data[0]);
$data=substr($data,1);
return $temp;
}
function addServer($ip) {
$map = '';
$players = '';
$maxplayers = '';
$servername = '';
$output = '';
$live_server = '0';
$packet = '0';
$packet = "\xFF\xFF\xFF\xFFTSource Engine Query\x00";
$live_server = fsockopen("udp://".$ip);
if(!$live_server)
{
$output = "Off";
}
else
{
fwrite($live_server, $packet);
socket_set_timeout($live_server,1,0);
$junk = fread($live_server,5);
$status = socket_get_status($live_server);
$do = 1;
$server_info= "";
while($do)
{
$str_1 = fread($live_server,1);
$server_info .= $str_1;
$status = socket_get_status($live_server);
if($status["unread_bytes"] == 0) {$do = 0;}
}
fclose($live_server);
if (strlen($server_info) > 0)
{
$success = 1;
$junk = getnextstring($server_info);
$servername = getnextstring($server_info);
$map = getnextstring($server_info);
$junk = getnextstring($server_info);
$junk = getnextstring($server_info);
$players = getnextbytevalue($server_info);
}
if ($players != '') {
$players = $players;
} else {
$players = "0";
}
if ($maxplayers != '')
{
$maxplayers = $maxplayers;
}
else
{
$maxplayers = "0";
}
if ($output != "Full" and $players != "0" or $maxplayers != "0")
{
$output = $output;
}
else
{
$output = "<font color='#FF0000'>Offline</font>";
}
if ($map != '')
{
$map = $map;
}
else
{
$map = "--";
$maxplayers = "--";
$players = "--";
}
if ($servername != '') {
$servername = $servername;
}
else
{
$servername = "--";
}
}
if($players == $maxplayers && $players != '--')
{
$players = "" . $players . "";
}
else if($players > $maxplayers-3 && $players != '--')
{
$players = "" . $players . "";
}
else
{
$players = "" . $players . "";
}
if ( strlen($map) > 19 )
{
$map = substr($map, 0, 19) . '...';
}
echo "
<tbody>
<tr style='background: #10130d;'>
";
if ($map == '--')
{
echo "<td><span style='background-color: #b85c5c; border-radius: .25em; padding: .2em .6em .3em; font-weight: bold; color: #fff; font-size: 10pt;'>Offline</i></span></td>";
}
else
{
echo "<td><span style='background-color: #5cb85c; border-radius: .25em; padding: .2em .6em .3em; font-weight: bold; color: #fff; font-size: 10pt; '>Online</i></span></td>";
}
echo "
<td><span style='color: #fff; font-size: 10pt;'>". $ip ."</span></td>
<td><span style='text-shadow: 0 0 10px #ffca00; color: #ffca00; font-size: 20pt;'>". $players ."</span></td>
</tr>
</tbody>
";
}
openserveriai();
include ('servers.php');
closeserveriai();
?>
</table>
</body>
</html>
You can do something like this
<?php
$total = 5;
if ($total >= 5 && $total <= 9) {
//Between 5 and 9
} else {
// Not between 5 and 9
}
?>
<table class='table table-bordered table-striped'>
<tbody>
<tr>
<td><span>First</span></td>
<td><span>Second</span></td>
<td><span><?php echo $total; ?></span></td>
</tr>
</tbody>
</table>
Then you can call that php page with
require('yourpage.php');

Categories