user ID and Dropdown sql php server side - php

the code for the view page:
<table id='display'>
<thead>
<tr>
<th>ID</th>
<th>NAME</th>
<th>DEPARTMENT</th>
<th>TELEFON</th>
<th>FAKS</th>
<th>E-MAIL</th>
<th>DATA</th>
<th>PURPOSE</th>
<th>ACTION</th>
</tr>
</thead>
<tbody>
<?php
$connect = mysql_connect("localhost","root","");
if (!$connect){
die(mysql_error());
}
mysql_select_db("permohonan_data");
$option = '';
$results = mysql_query("SELECT * FROM pemohon ORDER BY id DESC");
$option .='<select>';
while ($row = mysql_fetch_array($results)){
?>
<tr>
<td><?php echo $row['id']?></td>
<td><?php echo $row['name']?></td>
<td><?php echo $row['unit']?></td>
<td><?php echo $row['telefon']?></td>
<td><?php echo $row['faks']?></td>
<td><?php echo $row['email']?></td>
<td><?php echo $row['data']?></td>
<td><?php echo $row['purpose']?></td>
<td><?php echo $option .="<option value='" .$row['action']. "'>".$row['action']."</option>"?></td>
</tr>
<?php
}
$option .='</select>';
?>
</tbody>
</table>
the ouput:
the full detail contains id, name, position, department, institute, email, telefon and so on which doesnt show on the table because of lack of space. my question is, how when I clicked the ID number(auto increrment) of any user, I could see the full details of the user? like in a popup form?
and my dropdown for action column are empty, supposedly have 'approve' and 'disapprove' option but I didnt know how to insert that because its for admin to valid the thing, not the user. so I can't put the option on the client side where the user is. how can I create a new client side just for admin?
idk. please help. :(

change
<td><?php echo $row['id']?></td>
to
<td><?php echo "<a href='full_details.php?id=".$row['id']."'>".$row['id']."</a>" ?></td>
create a page called full_details.php and use the id to query the db

Using jQuery you can do that.
using a click event you can send id to a "full_details" page and show using a popup the data that page returns back.
See here: jquery.com
To use jquery you have include it on your page using tag and after that you can write your own function to receive click action on the id and after that you can send async request to your page and show the result without reload the page.

Related

How to hide table rows that fetch the info from a database based on string given and when a button is pressed

An HTML table is given in which there are people (agents in this case) who have the following information displayed Id, Name, Rank, Location, and Status. Status can have 3 values. Online, Offline, Disconnected. Based on the status that one of the agents has I want to put 3 buttons as such Online, Offline, and Disconnected, and when a button is pressed to hide the other rows with different values. For example, if I press Online, table rows on the HTML side that contain the status Offline and Disconnected disappear, this goes for the others too the other way around. I have no idea to achieve what I said earlier and I am open to any solution that is deemed to resolve my problem.
<table id="main_table">
<tr>
<td>Id</td>
<td>Agent Name</td>
<td>Agent Rank</td>
<td>Agent Location</td>
<td>Status</td>
</tr>
<?php
require 'CMS/processing/conn.php';
$result = mysqli_query($con,"SELECT * FROM agents");
while($info = mysqli_fetch_array($result)) {
?>
<tr>
<td><?php echo $info['id']; ?></td>
<td><?php echo $info['agentName']; ?></td>
<td><?php echo $info['agentRank']; ?></td>
<td><?php echo $info['locationNames']; ?></td>
<td><?php echo $info['agentStatus']; ?></td>
</tr>
<?php
}
?>
</table>
Try using the below logic : Create 3 buttons with <a> and pass status value as GET to the same page then while fetching check whether it has GET or not
Note:This is not a answer :passing direct GET value to sql query may cause some security issues
Online//put the status value based on your status
Offline//put the status value based on your status
Disconnected//put the status value based on your status
<table id="main_table">
<tr>
<td>Id</td>
<td>Agent Name</td>
<td>Agent Rank</td>
<td>Agent Location</td>
<td>Status</td>
</tr>
<?php
require 'CMS/processing/conn.php';
if(isset($_GET['status']))
{
$result = mysqli_query($con,"SELECT * FROM agents where agentStatus='".$_GET['status']."'");
}
else
{
$result = mysqli_query($con,"SELECT * FROM agents");
}
while($info = mysqli_fetch_array($result)) {
?>
<tr>
<td><?php echo $info['id']; ?></td>
<td><?php echo $info['agentName']; ?></td>
<td><?php echo $info['agentRank']; ?></td>
<td><?php echo $info['locationNames']; ?></td>
<td><?php echo $info['agentStatus']; ?></td>
</tr>
<?php
}
?>
</table>
I'd use javascript within a tag or jQuery since this sounds like you need dynamic functionality on a static webpage.
For your button pass in the name of the function you're creating inside your tag
<button onclick="yourFunctionName(yourString)"></button>
Inside your tag have the function accept the yourString paramater
function yourFunctionName(yourString){
if(yourString === "whatever"){
$('tbody tr').hide()
$('tbody tr').show()
}
etc! Let me know if you need any more clarification on anything
Output echo an attribute on each row <tr data-status="online"> etc.
Then in script use document.querySelectorAll("tr[data-status='online'] to find all rows with that status, loop thru the array and toggle each row style.display to 'table-row' or 'none' as required.
You could also do the same using CSS by assigning a class <tr class="online"> etc. Then in script dynamically altering the CSS definition of that class, changing the display to 'table-row' or 'none' as required.

how to add my database on a html table using session variables in php

I have a website that has multiple users that submit some requests, So each user will have his own Requests table that has been made. my issue is I'm trying to show the requests for every user in a table by using the session variables to get the name of the user and match it with the request table but it dose not work.
$userin= $_SESSION['username'];
$req = "SELECT * FROM request_table where r_status='pending' AND requester = 'max';";
$request_table = $conn->query($req);
it works if I out ( Max ) only but when I put it as a session variable or as $userin it dose not work and I get this error :
Notice: Trying to get property 'num_rows' of non-object in C:\xampp\htdocs\website\b_table.php on line 54.
Below is my code for the table :
<body>
<h1 align="center">Table</h1>
<table border="5" align="center" style="line-height:20px;">
<tr>
<th>Request ID</th>
<th>Requester name</th>
<th>Customer name</th>
<th>Description</th>
<th>Submition Date</th>
<th>Request Status</th>
<th>link</th>
</tr>
<?php
//Fetch Data form database
if($request_table->num_rows > 0){
while($view_request = $request_table->fetch_assoc()){
?>
<tr>
<td><?php echo $view_request['request_id']; ?></td>
<td><?php echo $view_request['requester']; ?></td>
<td><?php echo $view_request['customer_name']; ?></td>
<td><?php echo "Site A is:". $view_request['site_a']. ",<br> Site B is: ".$view_request['site_b']. ",<br>NO. Of links =:".$view_request['no_oflinks']; ?></td>
<td><?php echo $view_request['sub_date']; ?></td>
<td><?php echo $view_request['request_status']; ?></td>
<form action="view_request.php" method="GET"><td><button type="vieww" name="vieww" value= <?php echo $view_request['request_id']; ?>> View </button></td></form>
</tr>
<?php
}
}
else
{
?>
<tr>
<th colspan="7">No Data availabe</th>
</tr>
<?php
}
$conn->close();
?>
</table>
``````````````````````````````````````````````````````````````````````````````````````````
[enter image description here][1]
[1]: https://i.stack.imgur.com/pOHOX.jpg
you can do some debugging and testing.
like check if session variable is set or not like :
if(isset($_SESSION['username'])){
$userin= $_SESSION['username'];
}
else{
die("Session user name wasn't set");
}
and for the query
$req = "SELECT * FROM request_table where r_status='pending' AND requester = '$userin';"
for more debugging and testing , you can use vardump to check if data is present or not like : vardump($request_table);
hope it helps you in some way...
hope it helps.

create a clickable link in MySQL results

I'm in the process of learning some coding. I am looking to create the results of MySQL results clickable. I would like the name (first and last name) to be "clickable" so they can link to the customer record to view. Thanks in advance for your help!
<table class="list"; >
<tr>
<th>Name</th>
<th>Address</th>
<th>Email</th>
<th>Phone</th>
</tr>
<?php while($customers = mysqli_fetch_assoc($customer_set)) { ?>
<tr>
<td><?php echo h($customers['first_name'].' '.$customers['last_name']); ?></td>
<td><?php echo h($customers['address1']. ' '.$customers['city'].', '.$customers['state'].' '.$customers['zip']); ?></td>
<td><?php echo h($customers['email1']); ?></td>
<td><?php echo h($customers['phone1']); ?></td>
</tr>
<?php } ?>
Thanks,
If you want clickable first name and last name then you need to add anchor tag with view url like below examples.
Example (send first name and last name separately)
<td><?php echo h($customers['first_name'].' '.$customers['last_name']); ?></td>
Better solution is you can send id of user . For example i am asuming you have one column id in customers table then you can pass id like below example
<td><?php echo h($customers['first_name'].' '.$customers['last_name']); ?></td>
Note: You can encrypt id by using some hash methods to securely pass id of user.
Now when you click on these links you will redirect on view page where you can get these id or firstname, lastname by using GET method.
Example
view-record.php
<?php
if(isset($_GET['uid'])) {
$userid = $_GET['uid']; //please add some validation before using this value.
}
?>
You need to use the <a> (anchor) html tag like this:
<table class="list"; >
<tr>
<th>Name</th>
<th>Address</th>
<th>Email</th>
<th>Phone</th>
</tr>
<?php while($customers = mysqli_fetch_assoc($customer_set)) { ?>
<tr>
<td><?php echo h($customers['first_name'].' '.$customers['last_name']); ?></td>
<td><?php echo h($customers['address1']. ' '.$customers['city'].', '.$customers['state'].' '.$customers['zip']); ?></td>
<td><?php echo h($customers['email1']); ?></td>
<td><?php echo h($customers['phone1']); ?></td>
</tr>
<?php } ?>
Replace the url http://example.com/... with whatever real url you want to use for the link.

First result from DB not showing when using while loop

I am creating a php script to generate reports based on data stored in SQL, The query is here:
$sql = $adb->query("SELECT firstname, lastname, policynumber, isatype, isaname, startdate, unitvalue, numberofunits, currentamount, date, newunitvalue, newnumberofunits, newcurrentamount
FROM vtiger_isa, vtiger_addisa, vtiger_contactdetails
WHERE vtiger_isa.relatedclient = vtiger_addisa.addrelatedclient
AND vtiger_addisa.addrelatedclient = vtiger_contactdetails.contactid
AND vtiger_isa.relatedclient = $clientid
AND vtiger_isa.policynumber = $polnum
AND vtiger_addisa.addrelatedclient = $clientid
AND vtiger_addisa.newpolicynumber = $polnum
ORDER BY date ASC"
);
This performs fine as I have tested by using print_r($sql); and the results I want are there. Although when I am looping through the results they do not show. I have tested with different clientid's and the first result seems to missed out.
<b> New Figures:</b>
<table style="width:100%">
<tr>
<th>Date</th>
<th>Unit Value (P)</th>
<th>Number of Units</th>
<th>Total Value (£)</th>
</tr>
<?php
while ($sql->fetchInto($row)) {
?>
<tr>
<td><?php echo $row['date'];?></td>
<td><?php echo $row['newunitvalue'];?></td>
<td><?php echo $row['newnumberofunits'];?></td>
<td><?php echo $row['newcurrentamount'];?></td>
</tr>
<?php
}?>
</table>
</body>
</html>
I am not using the fetchInto() method. I using the following example:
<?php
$sql = $adb->query("...");
foreach($sql as $row){
?>
<tr>
<td><?php echo $row['date'];?></td>
<td><?php echo $row['newunitvalue'];?></td>
<td><?php echo $row['newnumberofunits'];?></td>
<td><?php echo $row['newcurrentamount'];?></td>
</tr>
<?php
}
?>
This is working every time. Try it out.

Click table row to load new table

So I have a table loaded on the my page, Is it possible to click on a row and have it load another table with the same ID from my database? For instance a table with customer orders is already loaded, when i click on one of the rows is it possible to have a second table load with the order record with the same id?
This is my code loading the first table. I was thinking maybe i could use a check box value? Or maybe some sort of jquery all though I dont know much about jquerys
I was able to find this code that prints the selected row to a message box but Im not sure how or even if it can do what ive described?
this is essentially what i want to do http://www.youtube.com/watch?v=cobidLA_KVU&feature=youtu.be
<table border="5",th,td, cellspacing="5", cellpadding="5", width="500", align="center">
<tr>
<th>TP ID</th>
<th>Permit Deny</th>
<th>Level</th>
<th>Session</th>
<th>Information Specialist</th>
</tr>
<?php foreach ($results as $row): ?>
<tr>
<td><?php echo $row->TP_ID ?></td>
<td><?php echo $row->Permit_or_Deny ?></td>
<td><?php echo $row->Level ?></td>
<td><?php echo $row->Session ?></td>
<td><?php echo $row->Information_specialist ?></td>
</tr>
<?php endforeach ?>
</table>
var i = 1;
$('td').each(function(){
$(this).addClass('col'+i);
i = i+1;
});
$('table').find("td:not(.col4)").on('click',function(){
alert($(this).text());
})
You can also use jQuery/Ajax. Make a $_GET from it and request the server for a new GET variable.

Categories