Array variable link to another page - php

Currently I am stuck. I have to get an overview of domains. These have to link to an record page. The problem is, I don't know how. I have tried to set an $_SESSION, but then it picks the first variable of my array. At the moment things are hardcoded with 1 example.
<?php
unset($command);
$command = array(
"command" => "DomainsListActive"
);
$api = new Versio_api();
$versio = $api->api_send($command);
if($versio['success']==0) {
echo("Fout opgetreden. Fout code: ".$versio['command_response_code'].". Fout text: ".$versio['command_response_message']."");
}
else {
if($versio['total_count']>0)
{
require_once("includes/submenu.php");
?>
<div class="col-sm-9 col-md-9" style="width:80%;">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Klantenpaneel</h3>
</div>
<div class="panel-body">
<form method="post" action="">
<table class="table table-striped">
<thead>
<tr>
<th>Domein</th>
<th>TLD</th>
<th>Verloop datum</th>
<th>Automatisch verlengen</th>
</tr>
</thead>
<table class="table table-striped table-bordered">
<tbody>
<?php
$teller = 1;
while($versio['total_count']>=$teller) {
?>
<tr>
<td><?php echo $versio['id_'.$teller]; ?></td>
<td><?php echo $versio['domain_'.$teller]; ?> </td>
<td><?php echo $versio['tld_'.$teller]; ?></td>
<td><?php echo $versio['expiration_date_'.$teller]; ?></td>
<td><?php echo $versio['auto_renew_'.$teller]; ?></td>
</tr>
<?php $teller++; } ?>
</tbody>
</table>
</form>
</div>
</div>
<?php
} else {
echo("Er zijn geen DNS records gevonden voor dit domein.");
}
}
?>
I have to get for example, the third variable of $versio['domain_'.$teller] to put in my array in antoher document, record.php. If there is somebody who could help me that would be awesome!

If I understand you correctly, could you pass the variables in a query string?
eg:
<a href="records.php?domain=<?php echo $versio['domain_'.$teller]; ?>&tld=<?php echo $versio['tld_'.$teller]; ?>">
<?php echo $versio['domain_'.$teller]; ?>
</a>
Then in records.php you could get those values with:
<?php
$domain = $_GET['domain'];
$tld = $_GET['tld'];

Related

How do i hide my table in first time and show after user search something?

i'm trying to build a website where users can find location of my company, but i need to hide the information at the first time and only show the location that users needed.
Here's my code:
<?php
$condition = '';
if(isset($_REQUEST['Kota']) and $_REQUEST['Kota']!=""){
$condition .= ' AND Kota LIKE "%'.$_REQUEST['Kota'].'%" ';
}
if(isset($_REQUEST['Outlet']) and $_REQUEST['Outlet']!=""){
$condition .= ' AND Outlet LIKE "%'.$_REQUEST['Outlet'].'%" ';
}
if(isset($_REQUEST['Alamat']) and $_REQUEST['Alamat']!=""){
$condition .= ' AND Alamat LIKE "%'.$_REQUEST['Alamat'].'%" ';
}
$userData = $db->getAllRecords('lokasi','*',$condition,'ORDER BY id DESC');
?>
<div>
<table class="table table-striped table-bordered">
<thead>
<tr class="bg-primary text-white">
<th>No</th>
<th>Cabang GO</th>
<th>Nama Kota</th>
<th>Alamat Outlet</th>
<th>No Telepon</th>
</tr>
</thead>
<tbody>
<?php
$s = '';
foreach($userData as $val){
$s++;
?>
<tr>
<td><?php echo $s;?></td>
<td><?php echo $val['Kota'];?></td>
<td><?php echo $val['Outlet'];?></td>
<td><?php echo $val['Alamat'];?></td>
<td><?php echo $val['Nomor'];?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
Start out with <div style=visibility:hidden>. Later change it to 'visible' using JavaScript code.
All the Code you have added is fine, you need few more things to add and it will be all working.
Add HTML Form with an input field for entering searching location and a submit button.
<form action="" method="post">
Search Location: <input type="text" name="location"> <input type="submit" name="submit">`enter code here`
</form>
Add "if" Condition to check the user submitted the form and the result from the db is not empty before the table, where you are displaying all the locations.
<?php if(isset($_POST['submit']) && count($userData) > 0){ ?>
<table class="table table-striped table-bordered">
<thead>
<tr class="bg-primary text-white">
<th>No</th>
<th>Cabang GO</th>
<th>Nama Kota</th>
<th>Alamat Outlet</th>
<th>No Telepon</th>
</tr>
</thead>
<tbody>
<?php
$s = '';
foreach($userData as $val){
$s++;
?>
<tr>
<td><?php echo $s;?></td>
<td><?php echo $val['Kota'];?></td>
<td><?php echo $val['Outlet'];?></td>
<td><?php echo $val['Alamat'];?></td>
<td><?php echo $val['Nomor'];?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>

Responsive table won't react to PHP, but it reacts to HTML

I put PHP codes inside my HTML table. This makes table don't work again. It search status will not work, and show entries won't change, beside that, after what I get 11 datas inside the table, it will show only 10 in it and won't create page two.
But, If I put manually with HTML, it works fine. What's the problem? If I create manually inside HTML 's it works fine.
include_once 'info.php';
$query = $config -> prepare("SELECT `banID`, `user_banned`, `ban_reason`, `ban_time`, `user_banner`, `ban_timestamp` FROM `samp_ban` ORDER BY `banID` DESC LIMIT 10");
if($query -> execute())
{
$query_results = $query->fetchAll();
} foreach( $query_results as $query_result ) {
if($query_result["ban_time"] == 0) { $query_result["ban_time"] = "Permanent"; }}
?>
<div class="contentpanel">
<ol class="breadcrumb breadcrumb-quirk">
<li><i class="fa fa-home mr5"></i> Home</li>
<li>Non Grata List</li>
</ol>
<div class="panel">
<div class="panel-heading">
<h4 class="panel-title">Non GrataLIST</h4>
<p>Here's the non grata list.</p>
</div>
<div class="panel-body">
<div class="table-responsive">
<table id="dataTable1" class="table table-bordered table-striped-col">
<thead>
<tr>
<th>ID</th>
<th>USER</th>
<th>REASON</th>
<th>TIME</th>
<th>ADMIN</th>
<th>DATA</th>
</tr>
</thead>
<?php foreach( $query_results as $query_result ) {
if($query_result["ban_time"] == 0) { $query_result["ban_time"] = "Permanent"; } ?>
<tbody>
<tr>
<td><?php echo $query_result["banID"]; ?></td>
<td><?php echo $query_result["user_banned"]; ?></td>
<td><?php echo $query_result["ban_reason"]; ?></td>
<td><?php echo $query_result["ban_time"]; ?> </td>
<td><?php echo $query_result["user_banner"]; ?></td>
<td><?php echo $query_result["ban_timestamp"]; ?></td>
</tr><?php } ?>
</tbody>
</table>
</div>
</div>
</div><!-- panel -->
</div><!-- contentpanel -->
The only thing I can see that might be problematic with this code is that you open the table body tag in the foreach loop, but close it outside of the loop. So I would suggest opening you table body tag before the foreach loop:
<tbody>
<?php
foreach( $query_results as $query_result ) {
if($query_result["ban_time"] == 0) { $query_result["ban_time"] = "Permanent"; } ?>
<tr>
<td><?php echo $query_result["banID"]; ?></td>
<td><?php echo $query_result["user_banned"]; ?></td>
<td><?php echo $query_result["ban_reason"]; ?></td>
<td><?php echo $query_result["ban_time"]; ?> </td>
<td><?php echo $query_result["user_banner"]; ?></td>
<td><?php echo $query_result["ban_timestamp"]; ?></td>
</tr>
<?php } ?>
</tbody>

Generate multiple table (For viewing)

I would like to ask on how to make my table to appear as following:
But I only manage to get my table to appear like this:
As you can see, the table is separated according to the different year or semester of when they stored their stuff. It is basically a history storage of that particular person. Unfortunately, I don't know how to make the generated table to attach together for the one with same year and semester instead of separating it. Even the numbering is affected. Below is the code that I have so far:
<?php
include("connect.php");
include("header.php");
if(isset($_GET['invstuview_bag'], $_GET['invstuview_name']))
{
$get_id = $_GET['invstuview_bag'];
$get_name = $_GET['invstuview_name'];
?>
<br/>
<ul class="breadcrumb">
<li class="breadcrumb-item">View History</li>
<li class="breadcrumb-item-active">Baggage Detail History</a></li>
</ul>
<div id="cssword">Baggage Detail History For <?php echo $get_name; ?>(<?php echo $get_id; ?>)</div>
<div class="container" style="width:70%;">
<div class="table-responsive">
<?php
$sql_join = "SELECT student.*,location.*, inventory.*, baggage.*
FROM
student,location, inventory, baggage
WHERE
student.student_id = inventory.invstu_id AND
baggage.baggage_id = inventory.invbag_id AND
location.location_id = inventory.invloc_id AND
invstu_id = '$get_id'
ORDER BY inventory_id";
$result_join= mysqli_query($connect,$sql_join);
$prev_year = "";
$prev_sem = 0;
$get_year = "";
$get_sem = 0;
while($row_join=mysqli_fetch_assoc($result_join))
{
$counter = 1;
$prev_year = $row_join["invstu_year"];
$prev_sem = $row_join["invstu_sem"];
//if the data is of same year and semester
if(($prev_year!="") && ($prev_sem!=0) && ($prev_year == $get_year) && ($prev_sem == $get_sem))
{
$get_year = $row_join["invstu_year"];
$get_sem = $row_join["invstu_sem"];
?>
<table class="table table-bordered">
<tr>
<th>No.</th>
<th>Baggage Types</th>
<th>Quantity</th>
<th>Location</th>
</tr>
<tr>
<td><?php echo $counter; ?></td>
<td><?php echo $row_join["baggage_type"]; ?></td>
<td><?php echo $row_join["invbag_quantity"]; ?></td>
<td><?php echo $row_join["location_house"]; ?></td>
</tr>
<?php
$counter++;
echo'</table>';
}
//if data is not of same year or semester
else
{
$get_year = $row_join["invstu_year"];
$get_sem = $row_join["invstu_sem"];
?>
</br></br>
Room: <?php echo $row_join["invstu_room"]; ?><br/>
Year: <?php echo $row_join["invstu_year"]; ?><br/>
Semester: <?php echo $row_join["invstu_sem"]; ?><br/>
<table class="table table-bordered">
<tr>
<th>No.</th>
<th>Baggage Types</th>
<th>Quantity</th>
<th>Location</th>
</tr>
<tr>
<td><?php echo $counter; ?></td>
<td><?php echo $row_join["baggage_type"]; ?></td>
<td><?php echo $row_join["invbag_quantity"]; ?></td>
<td><?php echo $row_join["location_house"]; ?></td>
</tr>
<?php
$counter++;
echo'</table>';
}
}
?>
</div>
<div align="right">
<button type="button" name="back" class="btn btn-success" id="back" style="width:200px; display:inline-block; margin-top:2%; margin-bottom:1%; background-color: #4CAF50" onclick="window.location.href='view.php'">Back</button>
</div>
</div>
<?php
}
?>
Any ideas is highly appreciated.
Move these out of the while loop:
<table class="table table-bordered">
<tr>
<th>No.</th>
<th>Baggage Types</th>
<th>Quantity</th>
<th>Location</th>
</tr>
echo'</table>';

PHP show records from one ID

Currently I have an overview of domains. I logged in with an account that has the contact ID of 197246. but it shows all of them. Here I want to filter my overview that the user which is logged in, sees his own domains.
So when ID 197246 logs in, show the domains that have contact id 197246. When ID 307890 logs in, show those domains.
This is my code so far. I guess here needs to be a filter.
<?php
unset($command);
$command = array(
"command" => "DomainsListActive"
);
$api = new Versio_api();
$versio = $api->api_send($command);
if($versio['success']==0) {
echo("Fout opgetreden. Fout code: ".$versio['command_response_code'].". Fout text: ".$versio['command_response_message']."");
}
else {
if($versio['total_count']>0)
{
require_once("includes/submenu.php");
?>
<div class="col-sm-9 col-md-9" style="width:80%;">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Klantenpaneel</h3>
</div>
<div class="panel-body">
<form method="post" action="">
<table class="table table-striped">
<thead>
<tr>
<th>Domein</th>
<th>TLD</th>
<th>Verloop datum</th>
<th>Automatisch verlengen</th>
<th>contact ID</th>
</tr>
</thead>
<table class="table table-striped table-bordered">
<tbody>
<?php
$teller = 1;
while($versio['total_count']>=$teller) {
?>
<tr>
<td><a href="records.php?domain=<?php echo $versio['domain_'.$teller]; ?>&tld=<?php echo $versio['tld_'.$teller]; ?>">
<?php echo $versio['domain_'.$teller]; ?></a></td>
<td>.<?php echo $versio['tld_'.$teller]; ?></td>
<td><?php echo $versio['expiration_date_'.$teller]; ?></td>
<td><?php echo $versio['auto_renew_'.$teller]; ?></td>
<td><?php echo $versio['contactid_'.$teller]; ?></td>
</tr>
<?php $teller++;
}
?>
</tbody>
</table>
</form>
</div>
</div>
<?php
} else {
echo("Er zijn geen DNS records gevonden voor dit domein.");
}
}
?>
The documentation from Versio gives you an entire list of options in the call. One option you could do is check if the 'contactid_x' equals to the logged in user.
more information on their wiki right here
As an example, this would do the trick:
unset($command);
$command = array(
"command" => "DomainsListActive"
);
$api = new Versio_api();
$versio = $api->api_send($command);
if($versio['success']==0) {
echo("Fout opgetreden. Fout code: ".$versio['command_response_code'].". Fout text: ".$versio['command_response_message']."");
}
else {
if($versio['total_count']>0)
{
require_once("includes/submenu.php");
?>
<div class="col-sm-9 col-md-9" style="width:80%;">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Klantenpaneel</h3>
</div>
<div class="panel-body">
<form method="post" action="">
<table class="table table-striped">
<thead>
<tr>
<th>Domein</th>
<th>TLD</th>
<th>Verloop datum</th>
<th>Automatisch verlengen</th>
<th>contact ID</th>
</tr>
</thead>
<table class="table table-striped table-bordered">
<tbody>
<?php
$teller = 1;
while($versio['total_count']>=$teller) {
if ($versio['contactid_'. $teller] != 197246 ) continue;
?>
<tr>
<td><a href="records.php?domain=<?php echo $versio['domain_'.$teller]; ?>&tld=<?php echo $versio['tld_'.$teller]; ?>">
<?php echo $versio['domain_'.$teller]; ?></a></td>
<td>.<?php echo $versio['tld_'.$teller]; ?></td>
<td><?php echo $versio['expiration_date_'.$teller]; ?></td>
<td><?php echo $versio['auto_renew_'.$teller]; ?></td>
<td><?php echo $versio['contactid_'.$teller]; ?></td>
</tr>
<?php $teller++;
}
?>
</tbody>
</table>
</form>
</div>
</div>
<?php
} else {
echo("Er zijn geen DNS records gevonden voor dit domein.");
}
}
?>
make sure to replace the ID with the ID from the user on line 41

making a print button

I am trying to make a button that would print my database in a contact list format. Where they would be grouped under the Departments that the contacts are added to on the php forms. Like this: (BELOW IS MY CODE FOR THE CONTACT PAGE)
ADMIN
George George#snakdnasd 0282738292392
8432
IT DEPARTMENT
Tyler tyler#askdnasdksan 7492823829292 8321
I have looked around and have tried the usual commands like window.print and just print() but it just prints the actual php page.
<?php
require_once"connection.php";
$contacts = array();
$all_contacts = "select * from contacts where contact_status = '1'";
$sql_all_contacts = $conn->query($all_contacts);
$total_contacts = $sql_all_contacts->num_rows;
while ($row = mysqli_fetch_assoc($sql_all_contacts)) {
$contacts[] = $row;
}
?>
<!DOCTYPE html>
<html>
<head>
<?php include"includes/head.inc"; ?>
</head>
<body>
<div class="wrapper">
<!-- header section -->
<?php include"includes/header.inc"; ?>
<!-- content section -->
<div class="content">
<div class="floatl"><h1><?php echo $total_contacts ?> Contact(s) Total</h1></div>
<a class="floatr" href="insert_contact.php"><input class="cancel_contact_button" type="button" value="New Contact"></a>
<div class="clear"></div>
<hr class="pageTitle">
<table border ="1" style="width:100%" id="contactsTable" class="display">
<thead>
<tr align="left">
<th>Name:</th>
<th>Email:</th>
<th>Department:</th>
<th>Extension:</th>
<th>Cellphone:</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($contacts as $contact) {?>
<tr>
<td><?php echo $contact["name"];?></td>
<td><?php echo $contact["email"]; ?></td>
<td><?php echo $contact["department"]; ?></td>
<td><?php echo $contact["extension"]; ?></td>
<td><?php echo $contact["cellphone"]; ?></td>
<td><i class="fa fa-pencil"></i> | <i class="fa fa-trash-o"></i></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</body>
</html>

Categories