php host status from php mysql database - ping

Help me!!
Seem when i run the scripts, the output seems wrong :(
This is the output...
Here My Output
The 1st and 3rd entry is true, online
But the rest should be OFFLINE but the output shows all ONLINE
I think the problem is from foreach loop but I cannot figure out how to solve the problem
Please help me... :(
<table border="1">
<thead>
<tr>
<th>Entry</th>
<th>Host</th>
<th>Name</th>
<th>Location</th>
<th>Description</th>
<th>Availability</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM host_entry";
$no = 1;
//foreach($dbh->fetchAll(PDO::FETCH_ASSOC) as $row)
$dbhi = $dbh->query($sql);
foreach ($dbhi->fetchAll(PDO::FETCH_BOTH) as $data) {
?>
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $data['host_server']; ?></td>
<td><?php echo $data['host_name']; ?></td>
<td><?php echo $data['host_location']; ?></td>
<td><?php echo $data['host_desc']; ?></td>
<td>
<?php
$ip = $data["host_server"];
// Run the ping to the IP
exec ("ping -n 1 -w 1 $ip", $ping_output);
if(preg_match("/Reply/i", $ping_output[2])!==0) {
echo "<font color='green'><strong>Online!</strong></font>";
}
else if(preg_match("/Reply/i", $ping_output[2])===0){
echo "<font color='red'><strong>Offline!</strong></font>";
}
?>
</td>
</tr>
<?php
}
?>
</tbody>

Related

How do you get stats on a gmod darkrp server to display it on a website/

I want to display some stats in a website like this:
https://zarpgaming.com/index.php/leaderboards/darkrp/gangs
how do I do this ? I work mostly with front end so I don't really know where to start.
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Salary</th>
<th>Wallet</th>
</tr>
</thead>
<tbody>
<?php
$conn = mysqli_connect("yourip","username","pw","databasename");
$result = mysqli_query($conn, "SELECT * FROM tablename");
while ($row = mysqli_fetch_assoc($result)):
?>
<tr>
<td><?php echo $row['rpname']; ?></td>
<td><?php echo $row['salary']; ?></td>
<td><?php echo $row['wallet']; ?></td>
<?php endwhile; ?>
</tr>
</tbody>
</table>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-3.6.0/dt-1.13.1/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-3.6.0/dt-1.13.1/datatables.min.js"></script>
<script>
$(".table").DataTable();
</script>
this code works
got it from this video
https://www.youtube.com/watch?v=UN_BO_qlna8

Make rowspan when data has same value in codeigniter

I have some data in mysql database, some of them are have same value.
I already show it in my program:
But it is possible to make rowspan like this?
this is my code.
<tbody class="table-bordered">
<?php $i = 1;
foreach ($altrankq1 as $alt) : ?>
<tr>
<td class="text-center"><?= $i; ?></td>
<td class="text-center"><?= $alt['kode_alternatif']; ?></td>
<td class="text-center"><?= round(($alt['nilai_Q1']), 4); ?></td>
</tr>
<?php $i++;
endforeach; ?>
</tbody>
maybe u can check the 'nilai_q1' like this(?)
<tbody class="table-bordered">
<?php $i = 1; $a = null;
foreach ($altrankq1 as $alt) : ?>
<tr>
<td class="text-center">
<?php
$b = round(($alt['nilai_Q1']), 4);
if($a === $b) {
$i = $i - 1;
echo $i;
} else {
echo $i;
}
$a = $b;
?>
</td>
<td class="text-center"><?= $alt['kode_alternatif']; ?></td>
<td class="text-center"><?= round(($alt['nilai_Q1']), 4); ?></td>
</tr>
<?php $i++;
endforeach; ?>
</tbody>
nb: not tested yet and isnt rowspan
or trying with jquery, i found this answer in stackoverflow rowspan-table-if-values-is-the-same-in-php

how to display ticket where i want data from booking page in codeigniter

In the previous page i filled payment details and submited and it shows train booked and i want to print ticket but im not getting data of the present booking .i tried to get data with booking_id but its not retrieving data.i can get retrieve data with passenger_id but it is not unique bcz one user can book multiple trains so it shows first entry in the database if there are multiple entries by one passenger .but im not being to get data with booking_id.help me!!!!!!
model
public function viewtrain($booking_id=null)
{
if($booking_id)
{
$this->db->select('*');
$this->db->from('booked');
$this->db->where('booking_id=?');
$alltrains=$this->db->get();
return $alltrains->result();
}
}
view
<table class="table table-type " style="text-align:center">
<thead>
<tr>
<th scope="col">Train ID</th>
<th scope="col">Origin</th>
<th scope="col">Destination</th>
<th scope="col">Date</th>
<th scope="col">Arrival Time</th>
<th scope="col">Departure Time</th>
<th scope="col">Class</th>
<th scope="col">Price</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php if(count($alltrains)):?>
<?php foreach($alltrains as $alltrain): ?>
<tr class="table-type">
<td><?php echo $alltrain->booking_id; ?></td>
<td><?php echo $alltrain->origin; ?></td>
<td><?php echo $alltrain->destination; ?></td>
<td><?php echo $alltrain->date; ?></td>
<td><?php echo $alltrain->arrivaltime; ?></td>
<td><?php echo $alltrain->departuretime; ?></td>
<td><?php echo $alltrain->class; ?></td>
<td><?php echo $alltrain->price; ?></td>
<td>
<?php echo anchor("admin/edittrain/{$alltrain->train_id}",'Edit',['class'=>'btn btn-outline-primary','style'=>'font-size:15px;height:20px;width:40%;padding-top :0px;']); ?>
<?php echo anchor("admin/deletetrain/{$alltrain->train_id}",'Delete',['class'=>'btn btn-outline-danger','style'=>'font-size:15px;height:20px;width:50%;padding-top :0px;']); ?>
</td>
</tr>
<?php endforeach;?>
<?php else:?>
<tr>
<td></td>
<td></td>
<td></td>
<td><h4>NO Trains Available!!</h4></td>
<td></td>
<td></td>
<td></td>
</tr>
<?php endif;?>
</tbody>
</table>
Controller
public function ticket($booking_id=null)
{
$this->load->model('user_model');
$alltrains=$this->user_model->viewtrain($booking_id);
$this->load->view('ticket',['alltrains'=>$alltrains]);
}
The data is not being retrieved because the format is wrong in your model, I've written the correct format below, see if this helps you.
Model
if($booking_id)
{
$this->db->select('*');
$this->db->from('booked');
$this->db->where('booking_id', $booking_id);
$alltrains=$this->db->get();
return $alltrains->result();
}

SQL NOT IN, != what to use?

I've an csv file with plant code like X001, X005, X019...
In mysql table plantcode=username.
I want to fetch all the plantcodes from my DB table where username are not present in my CSV file and deleted =0.
mycode
<?php
$file = fopen("aa.csv","r");
echo "<pre>";
//print_r(fgetcsv($file));
?>
<tr>
<td width="10%"><label>Username</label></td>
<td width="10%"><label>service center id</label></td>
<td width="10%"><label>service center name</label></td>
</tr>
<?php
$arr= fgetcsv($file);
foreach ($arr as $k => $v) {
$q= "SELECT * FROM `service_center` WHERE `deleted` = 0 AND username NOT LIKE '$v'";
$r = mysql_query($q);
$nr = mysql_num_rows($r);
if ($nr > 0) {
WHILE ($rows = mysql_fetch_array($r)) {
?>
<td><?php echo $rows['username'] ?></td>
<td><?php echo $rows['service_center_id'] ?></td>
<td><?php echo $rows['service_center_name'] ?></td>
<?php
}
}
else{
?>
<tr>
<td><?php echo $k;?></td>
<td><?php echo $v; ?></td>
<td><?php echo "No service center found";}?></td>
</tr>
<?php
}
fclose($file);
?>
I get output for each query like this
If username=X008 then from CSV i dont get X008 for one loop and in the next loop I get X008 and ,dont get present value plant code, But I want something like this
select * from service_center WHERE username != "X001, X007.." AND deleted = 0;
use NOT IN($name_array)
Pass username array in NOT IN
select * from service_center WHERE username NOT IN ("X001", "X007") AND deleted = 0;

Arrange data in tables?

I retrieve the data from the database and tried to implement them in the table, but now I don't know how to arrange them in the table. My view is:
<?php include('inc/header.php');?>
<div class="main">
<table>
<thead>
<tr>ID:</tr>
<th>Name:</th>
</thead>
<tbody>
<tr>
<?php foreach ($view as $row) :?>
<?php $i = 1;?>
<?php echo "<td>".$row->audio."</td>";?>
<?php echo $i++;?>
<?php endforeach;?>
</tr>
</tbody>
</table>
</div>
<?php include('inc/footer.php');?>
I just want to make the place id increase from one to the as many records and arrange them into one table.
Your foreach loop should be like this
<tbody>
<?php
$i = 1;
foreach ($view as $row)
{
echo "<tr>";
echo "<td>".$i."</td>";
echo "<td>".$row->audio."</td>";
$i++;
echo "</tr>";
}
?>
</tbody>
And <thead> should be
<thead>
<tr>
<th>ID:</th>
<th>Name:</th>
</tr>
</thead>
Try This Code
<?php
$i=1;
foreach ($view as $row)
{
?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $row->audio;?></td>
</tr>
<?php
$i++;
} ?>
You can try this
<?php $i = 1;?>
<?php foreach ($view as $row) :?>
<tr>
<?php echo "<td>".$i++."</td>";?>
<?php echo "<td>".$row->audio."</td>";?>
</tr>
<?php endforeach;?>
Try the following code:
<?php
$i=0;//place the initial value outside the loop
foreach ($view as $row)
{
$i++;//increment the value
?>
<tr>
<td><?php echo $i;//display the value ?></td>
<td><?php echo $row->audio;?></td>
</tr>
<?php
} ?>