I am creating a document management system for my project. I just want to know if there is a possible way to achieve a back button like in the photo below.
see the photo here
Here is my code for the document management system:
index.php
<main class="page-content">
<div class="container-fluid">
<div class="breadcrumb">
<div class="item"> Document</div>
</div>
<div class="load-data">
<?php
require_once 'config.php';
$sql = "SELECT * FROM tbl_menu WHERE parent='0' ORDER BY sort ASC";
$folders = $db->prepare($sql);
$folders->execute();
$folder = $folders->fetchAll();
if ($folder) {
echo "<table>";
echo "<thead>
<tr>
<td>Label</td>
<td>Sort</td>
<td>Id</td>
</tr>
</thead>";
foreach ($folder as $folderr) {
echo "<tr class='folder-item'>";
if($folder['link'] == 'folder'){
echo" <td><i class'fa fa-folder'><a href='#' onclick='get_data(".$folderr['id'].")'>".$folderr['label']."</a></td>";
}else{
echo" <td><i class='fa fa-file'></i><a href='#' onclick='get_data(".$folderr['id'].")'>".$folderr['label']."</a></td>";
}
echo" <td>".$folderr['sort']."</td>
<td>".$folderr['id']."</td>
</tr>";
}
echo "</table>";
} else {
echo 'No folder/files found.';
}
?>
</div>
</div>
</main>
</div>
here's the script
<script>
function get_data(id){
$.ajax({
type : 'GET',
url : 'file.php',
data : 'folder=' + id,
success : function(response){
$('.load-data').html(response);
}
});
}
$('.folder-item a').on('click', function() {
var $this = $(this),
$bc = $('<div class="item"></div>');
$this.parents('td').each(function(n, td) {
var $a = $(td).children('a').clone();
$bc.append(' > ', $a);
});
$('.breadcrumb').html( $bc.prepend('Document') );
return false;
});
</script>
here's the file.php
<?php
require_once 'config.php';
if(isset($_GET['folder'])){
$id = $_GET['folder'];
$sql = "SELECT * FROM tbl_menu WHERE parent='$id' ORDER BY sort ASC";
$folders = $db->prepare($sql);
$folders->execute();
$folder = $folders->fetchAll();
if ($folder) {
echo "<table>";
echo "<thead>
<tr>
<td>Label</td>
<td>Sort</td>
<td>Id</td>
</tr>
</thead>";
foreach ($folder as $folderr) {
echo "<tr>";
if($folder['link'] == 'folder'){
echo" <td><i class'fa fa-folder'><a href='#' onclick='get_data(".$folderr['id'].")'>".$folderr['label']."</a></td>";
}else{
echo" <td><i class='fa fa-file'></i><a href='#' onclick='get_data(".$folderr['id'].")'>".$folderr['label']."</a></td>";
}
echo" <td>".$folderr['sort']."</td>
<td>".$folderr['id']."</td>
</tr>";
}
echo "</table>";
} else {
echo 'No folder/files found.';
}
}
?>
Related
I'm trying to get the Owner's details by clicking on their name from the table at the bottom.
<html>
<head>
<title>Home</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
window.onload = function()
{
timedHide(document.getElementById('co'), 10);
}
function timedHide(element, seconds)
{
if (element) {
setTimeout(function() {
element.style.display = 'none';
}, seconds*1000);
}
}
</script>
<?php
require 'Navbar.php';
?>
<h1>Welcome to Poppleton Dog Show! This year 50 owners entered 300 dogs in 10 events!</h1>
<?php
include './connection.php';
$sql = "SELECT owners.id AS id, owners.name AS Owner, owners.email AS Email, dogs.name AS Name, ROUND(avg(score), 1) AS avg_score, breeds.name AS breed_name, COUNT(entries.id) AS entries_count\n"
. "FROM entries\n"
. "JOIN dogs ON dogs.id = entries.dog_id\n"
. "JOIN breeds ON dogs.breed_id = breeds.id\n"
. "JOIN owners ON owners.id = dogs.owner_id\n"
. "GROUP BY dogs.id\n"
. "HAVING entries_count > 1\n"
. "ORDER BY `avg_score` DESC\n"
. "LIMIT 10";
$result = $conn->query($sql);
echo "<table '<td align='center'>
<tr>
<th>Owner</th>
<th>Email</th>
<th>Dog</th>
<th>Breed</th>
<th>Average Score</th>
</tr>";
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>". "" ."". $row['Owner']. "</td>";
echo "<td>". "" ."<a href= mailto:$row[Email]>$row[Email]</a></td>";
echo "<td>". "" . $row["Name"] . "</td>";
echo "<td>". "" . $row["breed_name"] . "</td>";
echo "<td>". "" . $row["avg_score"] . "</td>";
echo "</tr>";
}
echo "</table>";
$conn->close();
?>
<!-- connection message will fade away-->
<script>
$( document ).ready( readyFn );
$(function() {
$('#echo').fadeOut(1000);
});
</script>
</body>
</html>
my $_GET method on the other page is now taking the number but it's still not displaying the owner's details and no errors or anything. I don't know what's wrong with the code. A would appreciate any advice regarding code, formatting, etc.
<html>
<head>
<title>OwnerDetail</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
window.onload = function()
{
timedHide(document.getElementById('co'), 10);
}
function timedHide(element, seconds)
{
if (element) {
setTimeout(function() {
element.style.display = 'none';
}, seconds*1000);
}
}
</script>
<?php
require 'Navbar.php';
?>
<?php
include './connection.php';
?>
<?php
$id = $_GET['id']; // Collecting data from query string
if (!is_numeric($id)) { // Checking data it is a number or not
echo "Data Error";
exit;
}
$count=$dbo->prepare("SELECT * FROM owners WHERE id=:id");
$count->bindParam(":id",$id,PDO::PARAM_INT,3);
if($count->execute()){
echo " Success ";
$row = $count->fetch(PDO::FETCH_OBJ);
echo "<table>";
}
echo "
<tr bgcolor='#f1f1f1'><td><b>Name</b></td><td>$row->name</td></tr>
<tr><td><b>Class</b></td><td>$row->class</td></tr>
<tr bgcolor='#f1f1f1'><td><b>Mark</b></td><td>$row->mark</td></tr>
<tr><td><b>Address</b></td><td>$row->address</td></tr>
<tr bgcolor='#f1f1f1'><td><b>Image</b></td><td>$row->img</td></tr>
";
echo "</table>";
?>
<script>
$( document ).ready( readyFn );
$(function() {
$('#echo').fadeOut(1000);
});
</script>
</body>
</html>
You really should consider doing this:
Replace the ancient jQuery
Simplify the PHP which is already producing invalid HTML
Ajax the data only
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(function() {
$("#ownerTable a.owner").on("click", function(e) {
e.preventDefault(); // stop link
const ownerDetails = $.get(this.href, function(data) {
$("#output").html(data)
});
});
});
<script>
and have
<table>
<thead>
<tr>
<th>Owner</th>
<th>Email</th>
<th>Dog</th>
<th>Breed</th>
<th>Average Score</th>
</tr>
</thead>
<tbody id="ownerTable">
<? while($row = mysqli_fetch_assoc($result)) { ?>
<tr>
<td>
<a class="owner" href="OwnerDetails.php?id=<?= $row['id'] ?>"><?= $row['Owner'] ?></a>
</td>
<td>
<?= $row[Email] ?>
</td>
<td>
<?= $row["Name"] ?>
</td>
<td>
<?= $row["breed_name"] ?>
</td>
<td>
<?= $row["avg_score"] ?>
</td>
</tr>
<? } ?>
</tbody>
<tbody id="output"></tbody>
</table>
where Ownerdetails.php now looks like
<?php
$id = $_GET['id']; // Collecting data from query string
if (!is_numeric($id)) { // Checking data it is a number or not
echo "<tr><td>Data Error</td></tr>";
exit;
}
$count=$dbo->prepare("SELECT * FROM owners WHERE id=:id");
$count->bindParam(":id",$id,PDO::PARAM_INT,3);
if($count->execute()){
$row = $count->fetch(PDO::FETCH_OBJ);
echo "
<tr bgcolor='#f1f1f1'><td><b>Name</b></td><td>$row->name</td></tr>
<tr><td><b>Class</b></td><td>$row->class</td></tr>
<tr bgcolor='#f1f1f1'><td><b>Mark</b></td><td>$row->mark</td></tr>
<tr><td><b>Address</b></td><td>$row->address</td></tr>
<tr bgcolor='#f1f1f1'><td><b>Image</b></td><td>$row->img</td></tr>";
}
?>
I have been staring at this for literally two hours trying to fix it. Any help would be appreciated. For some reason the table isn't being loaded when the button is clicked.
Here's the relevant part of my head:
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css" />
</head>
This is my table:
<div class="container">
<div class="midtxt">
<div id = "transactions-sav" style="margin-top: 0;">
<h2>Most Recent Transactions</h2>
<table>
<thead>
<tr>
<th>Username</th>
<th>Amount</th>
<th>Time & Date</th>
<th>Account Type</th>
</tr>
</thead>
<tbody>
<div id="trans-div">
</div>
</tbody>
</table>
<hr />
</div>
</div>
<a class="btn light-blue waves-effect waves-light table-end" id="trans-more" style="margin-top: 35px;">Load More Transactions</a>
</div>
This is my Ajax transmitter:
<script>
$(document).ready(function() {
let transCount = 20;
$('#trans-more').on('click', function() {
transCount += 20;
console.log('click');
console.log(transCount);
$('#trans-div').load('includes/loadtranshistajax.inc.php', {transNewCount: transCount,user_id: <?php echo $_SESSION['user_id']; ?>}, function() {
console.log('callback');
});
});
console.log('test1');
});
</script>
This is my PHP script for generating the table. It is worth noting that initialize() starts a session.:
<?php
require_once 'dbc-stu.inc.php';
require_once 'initialize.inc.php';
require_once 'app/transactions/transhist.inc.php';
initialize();
initialize_secure();
//Import the count
$limit = $_POST['transNewCount'];
$userID = $_SESSION['user_id'];
$sql = "SELECT * FROM transactions WHERE trans_targetID ='$userID' ORDER BY trans_time DESC LIMIT $limit";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
while ($row = mysqli_fetch_assoc($result)) {
echo '<tr>';
foreach ($row as $key => $value) {
if ($key === 'trans_time') {
$time = $value;
date_default_timezone_set("America/Los_Angeles");
$time = date("F j, Y, g:i a",$time);
} elseif ($key === 'trans_amount') {
$amnt = $value;
} elseif ($key ==='trans_targetID') {
$username = idToUsername($value);
} elseif ($key === 'trans_accType') {
$accType = $value;
}
}
echo '<td>' . $username . '</td>';
echo '<td>' . $amnt . '</td>';
echo '<td>' . $time . '</td>';
echo '<td>' . $accType . '</td>';
echo '</tr>';
}
Edit, thanks a lot everybody. I'm fairly new to the web development community, so it's cool to see everyone help out!
Remove div tag from tag and add id in tbody attribute as below.
<tbody id="trans-div"></tbody>
Put the php code<?php echo $_SESSION['user_id']; ?> inside a <script> tag into double quote as it's causing the SyntaxError which break` your script code.
That's why you are not able to view XHR into console
Try the following:
$('#trans-div').load('includes/loadtranshistajax.inc.php', {transNewCount: transCount,user_id: "<?php echo $_SESSION['user_id']; ?>"}, function() {
console.log('callback');
});
The title may be a bit misleading as I didn't know exactly how to phrase it. I have a PHP page which shows a listing of records with search filters. The code is given below. The page gets displayed correctly but in one of the columns I get following database error for MS SQL
Error Number: 22018
[Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Conversion failed when converting the varchar value 'Marie Stopes International' to data type int.
SELECT * FROM ctbl_mas_funder WHERE flag = 0 AND id = 'Marie Stopes International'
Filename: C:\inetpub\wwwroot\FMS\system\database\DB_driver.php
Line Number: 330
I think its because instead of pulling an ID for query it is pulling the data from some other column, but cannot quite put my finger on what is causing this.
The code for the page is as below.
<link href="<?php echo base_url(); ?>assets/js/plugins/forms/select2/select2.css" rel="stylesheet" />
<script src="<?php echo base_url(); ?>assets/js/plugins/forms/uniform/jquery.uniform.min.js"></script>
<script src="<?php echo base_url(); ?>assets/js/plugins/forms/select2/select2.js"></script>
<script src="<?php echo base_url(); ?>assets/js/plugins/tables/datatables/jquery.dataTables.min.js"></script>
<script src="<?php echo base_url(); ?>assets/js/plugins/tables/datatables/jquery.dataTables.columnFilter.js"></script>
<script src="<?php echo base_url(); ?>assets/js/app.js"></script><!-- Core js functions -->
<script src="<?php echo base_url(); ?>assets/js/pages/data-tables.js"></script><!-- Init plugins only for page -->
<div class="wrapper">
<div class="crumb">
<ul class="breadcrumb">
<li><i class="icon16 i-home-4"></i>Home</li>
<li>Manage Funding</li>
<li class="active">
<?=$title ?>
</li>
</ul>
</div>
<div class="container-fluid">
<div id="heading" class="page-header">
<h1><i class="icon20 i-table-2"></i>
<?=$title ?>
</h1>
</div>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<div class="icon"><i class="icon20 i-table"></i></div>
<h4>
<?=$title ?>
</h4>
<div class="flexigrid" style="width: 100%;">
<div class="tDiv">
<div class="tDiv2">
<?php
$f_manange_funding=explode(',', $this->session->userdata('f_manange_funding'));
if (in_array('6', $m_projects) or $this->session->userdata('user_type')=='admin')
{?>
<!--<div class="fbutton tip" title="Download Word" onclick="javascript:document.location.href='<?php echo site_url("office").'/'.$this->uri->segment(2).'/'.$this->uri->segment(3); ?>/download_word'"><div><span class="word" style="padding-left: 20px;">Word</span></div></div>
<div class="btnseparator"></div>-->
<?php }
if (in_array('5', $m_projects) or $this->session->userdata('user_type')=='admin')
{?>
<!--<div class="fbutton tip" title="Download Excel" onclick="javascript:document.location.href='<?php echo site_url("office").'/'.$this->uri->segment(2).'/'.$this->uri->segment(3); ?>/download_excel'"><div><span class="excel" style="padding-left: 20px;">Excel</span></div></div> <div class="btnseparator"></div> -->
<?php }
if (in_array('7', $m_projects) or $this->session->userdata('user_type')=='admin')
{?>
<!--<div class="fbutton tip" title="Download Pdf" onclick="javascript:document.location.href='<?php echo site_url("office").'/'.$this->uri->segment(2).'/'.$this->uri->segment(3); ?>/download_pdf'"><div><span class="pdf" style="padding-left: 20px;">Pdf</span></div></div>
<div class="btnseparator"></div>-->
<?php }
if (in_array('8', $m_projects) or $this->session->userdata('user_type')=='admin')
{?>
<!--<div class="fbutton tip" title="Print" onclick="javascript:window.open('<?php echo site_url("office").'/'.$this->uri->segment(2).'/'.$this->uri->segment(3); ?>/print_page', 'mywindow', 'location=1,status=1,scrollbars=1, width=600,height=600')"><div><span class="print" style="padding-left: 20px;">Print</span></div></div>
<div class="btnseparator"></div>-->
<?php } ?>
<div class="fbutton tip" title="Help" >
<div><span class="help_ic" style="padding-left: 20px;">Help</span></div>
</div>
</div>
<div style="clear:both"></div>
</div>
</div>
</div>
<!-- End .panel-heading -->
<div class="panel-body">
<?php
//flash messages
if($this->session->flashdata('feedback'))
{
echo '<div class="alert alert-success">';
echo '<a class="close" data-dismiss="alert">×</a>';
echo $this->session->flashdata('feedback');
echo '</div>';
} ?>
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered table-hover" id="dataTable">
<thead>
<tr>
<th > Funding Hierarchy</th>
<th >Project Code </th>
<th >Country of implementation</th>
<th >Source of funding </th>
<th > Primary Donor</th>
<th > Contracting donor</th>
<th > Contracting recipient </th>
<th >Short Title</th>
<th >Funding status</th>
<th width="8%">Action</th>
</tr>
</thead>
<tbody>
<?php
$str="";
if(($funding_mechanism !="") or ($primary_donor !="") or ($contracting_donor_funder_code !="" ) or ($funder_code_primary !="" ) or ($funding_manager !="" ) ){
if($fundingstatus !="")
{
$str=$str."ctbl_contract_funding_info.fundingstatus ='$fundingstatus'";
}
if($project_code !="")
{
if($str!="")
{
$str=$str." and ";
}
$str=$str."ctbl_contract_funding_info.project_code='$project_code'";
}
if($fundingHierarchy !="")
{
if($str!="")
{
$str=$str." and ";
}
$str=$str."ctbl_contract_funding_info.fundingHierarchy='$fundingHierarchy'";
}
if($funding_mechanism !="")
{
if($str!="")
{
$str=$str." and ";
}
$str=$str."ctbl_contract_funding_fin.funding_mechanism='$funding_mechanism'";
}
if($subfunding_title !="")
{
if($str!="")
{
$str=$str." and ";
}
$str=$str."ctbl_contract_funding_info.subfunding_title='$subfunding_title'";
}
if($primary_donor !="")
{
if($str!="")
{
$str=$str." and ";
}
$str=$str."ctbl_contract_funding_info.primary_donor='$primary_donor'";
}
if($source_funding !="")
{
if($str!="")
{
$str=$str." and ";
}
// $str=$str."ctbl_contract_funding_info.source_funding='$source_funding'";
$str=$str."ctbl_contract_funding_info.source_funding REGEXP '.*;s:[0-9]+:\"$source_funding\".*'";
}
if($contracting_donor !="")
{
if($str!="")
{
$str=$str." and ";
}
$str=$str."ctbl_contract_funding_info.contracting_donor='$contracting_donor'";
}
if($contracting_recipient !="")
{
if($str!="")
{
$str=$str." and ";
}
$str=$str."ctbl_contract_funding_info.contracting_recipient='$contracting_recipient'";
}
if($funder_code_source !="")
{
if($str!="")
{
$str=$str." and ";
}
$str=$str."ctbl_contract_funding_info.funder_code_source='$funder_code_source'";
}
if($contracting_donor_funder_code !="")
{
if($str!="")
{
$str=$str." and ";
}
$str=$str."ctbl_contract_funding_info.contracting_donor_funder_code='$contracting_donor_funder_code'";
}
if($funder_code_primary !="")
{
if($str!="")
{
$str=$str." and ";
}
$str=$str."ctbl_contract_funding_info.funder_code_primary='$funder_code_primary'";
}
if($country_implemention !="")
{
if($str!="")
{
$str=$str." and ";
}
// $str=$str."ctbl_contract_funding_info.country_implemention='$country_implemention'";
$str=$str."ctbl_contract_funding_info.country_implemention REGEXP '.*;s:[0-9]+:\"$country_implemention\".*'";
}
if($funding_manager !="")
{
if($str!="")
{
$str=$str." and ";
}
$str=$str."ctbl_contract_funding_mgmt.funding_manager='$funding_manager'";
}
$query_search = $this->db->query('SELECT ctbl_contract_funding_info.* ,ctbl_contract_funding_mgmt.funding_manager,ctbl_contract_workflow.id as id1,ctbl_contract_workflow.family_id as main_id ,ctbl_contract_workflow.parent_type
FROM ctbl_contract_workflow
LEFT JOIN ctbl_contract_funding_info ON ctbl_contract_funding_info.contract_id = ctbl_contract_workflow.id
LEFT JOIN ctbl_contract_funding_mgmt ON ctbl_contract_funding_mgmt.contract_id = ctbl_contract_funding_info.contract_id
LEFT JOIN ctbl_contract_funding_fin ON ctbl_contract_funding_fin.contract_id = ctbl_contract_funding_mgmt.contract_id
WHERE '.$str.'
ORDER BY ctbl_contract_workflow.id asc');
$total=$query_search->num_rows() ;
foreach($query_search->result_array() as $row_search)
{
echo '<tr>';
echo '<td>'.$row_search['fundingHierarchy'].'</td>';
if($row_search['project_code']!='')
{
echo '<td>E'.$row_search['project_code'].'</td>';
}
else
{
echo '<td></td>';
}
if($row_search['country_implemention']=='')
{
$data['list1'] = $this->common_model->get_by_id('id',$country_implemention,'ctbl_mas_country');
echo '<td>'.$data['list1'][0]['name'].'</td>';
}
else
{
?>
<td><?php $query = $this->db->query('SELECT * FROM ctbl_mas_country order by rank desc');
$total=$query->num_rows() ;
if($total>0)
{
foreach ($query->result_array() as $row)
{
if(unserialize($row_search['country_implemention'])!='')
{
$implementing_agency= unserialize($row_search['country_implemention']);
}
else
{
$implementing_agency=array();
}
if (in_array($row['id'], $implementing_agency))
{
echo $row['name']."<br>";
}
}
}
?></td>
<?php
}
if($source_funding!='' || $source_funding!='Array')
{
$data['list'] = $this->common_model->get_by_id('id',$source_funding,'ctbl_mas_funder');
echo '<td>'.$data['list'][0]['name'].'</td>';
}
else
{
?>
<td><?php
$query = $this->db->query('SELECT * FROM ctbl_mas_funder Where flag=0 ');
$total=$query->num_rows() ;
if($total>0)
{
foreach ($query->result_array() as $row)
{
if(unserialize($row_search['source_funding'])!='')
{
$source_funding= unserialize($row_search['source_funding']);
}
else
{
$source_funding=array();
}
if (in_array($row['id']."-".$row['code'], $source_funding))
{
echo $row['name']."<br>";
}
}
}
?></td>
<?php
}
$data['list1'] = $this->common_model->get_by_id('id',substr($row_search['primary_donor'],0, strpos($row_search['primary_donor'], "-")),'ctbl_mas_funder');
echo '<td>'.$data['list1'][0]['name'].'</td>';
?>
<td><?php
$c=explode("-",$row_search['contracting_donor']);
if(is_array($c) && $c[1]!='')
{
$data['list2'] = $this->common_model->get_by_id('id',$c[0],'ctbl_mas_funder');
echo $data['list2'][0]['name'];
}
else
{
echo $row_search['contracting_donor'];
}
?></td>
<td><?php
if($row_search['contracting_recipient']!='Select')
{
if($row_search['type_recipient']!='Select')
{
if($row_search['type_recipient']=='MSI partnership')
{
if($row_search['contracting_recipient']!='Select')
{
$data['list_cd'] = $this->common_model->get_by_id('id',$row_search['contracting_recipient'],'ctbl_mas_msi_entities');
$d=$data['list_cd'][0]['name'] ;
}
else
{
$d='';
}
?>
<?php echo $d ; ?>
<?php
}
else if($row_search['type_recipient']=='External partner')
{
if($row_search['contracting_recipient']!='Select')
{
$data['list_cd'] = $this->common_model->get_by_id('id',$row_search['contracting_recipient'],'ctbl_mas_external_partners');
$d=$data['list_cd'][0]['name'] ;
}
else
{
$d='';
}
?>
<?php echo $d ; ?>
<?php
}
else if($row_search['type_recipient']=='MSI funding stream')
{
if($row_search['contracting_recipient']!='Select')
{
$data['list_cd'] = $this->common_model->get_by_id('id',$row_search['contracting_recipient'],'ctbl_mas_msi_funding_streams');
$d=$data['list_cd'][0]['name'] ;
}
else
{
$d='';
}
?>
<?php echo $d ; ?>
<?php
}
else if($row_search['type_recipient']=='MSI funding stream - project donor')
{
if($row_search['contracting_recipient']!='Select')
{
$data['list_cd'] = $this->common_model->get_by_id('id',$row_search['contracting_recipient'],'ctbl_mas_funder');
$d=$data['list_cd'][0]['name'] ;
}
else
{
$d='';
}
?>
<?php echo $d ; ?>
<?php
}
}}?></td>
<?php
echo '<td>'.$row_search['subfunding_title'].'</td>';
echo '<td>'.$row_search['fundingstatus'].'</td>';
echo '<td class="crud-actions">';
if($row_search['main_id']==$row_search['id1'])
{
echo '<i class="icon16 i-zoom-in"></i> ';
}
else
{
echo '<i class="icon16 i-zoom-in"></i> ';
}
//echo '<i class="icon16 i-pencil"></i> ';
//echo '<a class="tip" title="Delete" href="'.site_url("office").'/master/create_entry/delete/?contract_id='.$this->encryption->encode($row_search['id']).'" title="Remove"><i class="icon16 i-remove"></i></a>';
echo ' </td></tr>';
}
/// to show no records
/// to show no records
}else{
//// searching results query ends here
//// searching results query echo ends here
$query_search = $this->db->query('SELECT ctbl_contract_funding_info.* ,ctbl_contract_funding_mgmt.funding_manager,ctbl_contract_workflow.id as id1,ctbl_contract_workflow.family_id as main_id,ctbl_contract_workflow.parent_type
FROM ctbl_contract_workflow
LEFT JOIN ctbl_contract_funding_info ON ctbl_contract_funding_info.contract_id = ctbl_contract_workflow.id
LEFT JOIN ctbl_contract_funding_mgmt ON ctbl_contract_funding_mgmt.contract_id = ctbl_contract_workflow.id
LEFT JOIN ctbl_contract_funding_fin ON ctbl_contract_funding_fin.contract_id = ctbl_contract_funding_mgmt.contract_id
ORDER BY ctbl_contract_workflow.id asc');
$total=$query_search->num_rows() ;
foreach($query_search->result_array() as $row_search)
{
echo '<tr>';
echo '<td>'.$row_search['fundingHierarchy'].'</td>';
if($row_search['project_code']!='')
{
echo '<td>E'.$row_search['project_code'].'</td>';
}
else
{
echo '<td>'.$row_search['project_code'].'</td>';
}
?>
<td><?php $query = $this->db->query('SELECT * FROM ctbl_mas_country order by rank desc');
$total=$query->num_rows() ;
if($total>0)
{
foreach ($query->result_array() as $row)
{
if(unserialize($row_search['country_implemention'])!='')
{
$implementing_agency= unserialize($row_search['country_implemention']);
}
else
{
$implementing_agency=array();
}
if (in_array($row['id'], $implementing_agency))
{
echo $row['name']."<br>";
}
}
}
?></td>
<td><?php
$query = $this->db->query('SELECT * FROM ctbl_mas_funder Where flag=0 ');
$total=$query->num_rows() ;
if($total>0)
{
foreach ($query->result_array() as $row)
{
if(unserialize($row_search['source_funding'])!='')
{
$source_funding= unserialize($row_search['source_funding']);
}
else
{
$source_funding=array();
}
if (in_array($row['id']."-".$row['code'], $source_funding))
{
echo $row['name']."<br>";
}
}
}
?></td>
<?php
$data['list1'] = $this->common_model->get_by_id('id',substr($row_search['primary_donor'],0, strpos($row_search['primary_donor'], "-")),'ctbl_mas_funder');
echo '<td>'.$data['list1'][0]['name'].'</td>';
?>
<td>
<?php
//echo $row['contracting_donor'];
$code_id =explode("-",$row_search['contracting_donor']);
if(trim($row_search['fundingHierarchy']) == 'Donor Funding'){
$data['donor_name'] = $this->common_model->get_by_id('id',$code_id[0],'ctbl_mas_funder');
echo $data['donor_name'][0]['name'];
}
else{
echo $row_search['contracting_donor'];
}
?>
</td>
<td>
<?php
if($row_search['contracting_recipient']!='Select')
{
if($row_search['type_recipient']!='Select')
{
if($row_search['type_recipient']=='MSI partnership')
{
if($row_search['contracting_recipient']!='Select')
{
$data['list_cd'] = $this->common_model->get_by_id('id',$row_search['contracting_recipient'],'ctbl_mas_partnership');
$d=$data['list_cd'][0]['name'] ;
}
else
{
$d='';
}
?>
<?php echo $d ; ?>
<?php
}
else if($row_search['type_recipient']=='External partner')
{
if($row_search['contracting_recipient']!='Select')
{
$data['list_cd'] = $this->common_model->get_by_id('id',$row_search['contracting_recipient'],'ctbl_mas_external_partners');
$d=$data['list_cd'][0]['name'] ;
}
else
{
$d='';
}
?>
<?php echo $d ; ?>
<?php
}
else if($row_search['type_recipient']=='MSI funding stream')
{
if($row_search['contracting_recipient']!='Select')
{
$data['list_cd'] = $this->common_model->get_by_id('id',$row_search['contracting_recipient'],'ctbl_mas_msi_funding_streams');
$d=$data['list_cd'][0]['name'] ;
}
else
{
$d='';
}
?>
<?php echo $d ; ?>
<?php
}
else if($row_search['type_recipient']=='MSI funding stream - project donor')
{
if($row_search['contracting_recipient']!='Select')
{
$data['list_cd'] = $this->common_model->get_by_id('id',$row_search['contracting_recipient'],'ctbl_mas_funder');
$d=$data['list_cd'][0]['name'] ;
}
else
{
$d='';
}
?>
<?php echo $d ; ?>
<?php
}
}
}
?>
</td>
<?php
echo '<td>'.$row_search['subfunding_title'].'</td>';
echo '<td>'.$row_search['fundingstatus'].'</td>';
echo '<td class="crud-actions">';
if($row_search['main_id']==$row_search['id1'])
{
echo '<i class="icon16 i-zoom-in"></i> ';
}
else
{
echo '<i class="icon16 i-zoom-in"></i> ';
}
//echo '<i class="icon16 i-pencil"></i> ';
//echo '<a class="tip" title="Delete" href="'.site_url("office").'/master/create_entry/delete/?contract_id='.$this->encryption->encode($row_search['id']).'" title="Remove"><i class="icon16 i-remove"></i></a>';
echo ' </td></tr>';
}
}
?>
</tbody>
</table>
<?php require_once('help.php');?>
<div class="form-group">
<div class="col-lg-offset-4">
<div class="pad-left15"> <i class="i-cancel"></i>Cancel/Back </div>
</div>
</div>
</div>
<!-- End .panel-body -->
</div>
<!-- End .widget -->
</div>
<!-- End .col-lg-12 -->
</div>
<!-- End .row-fluid -->
</div>
<!-- End .container-fluid -->
</div>
The course name php is available in the table one time but when I retrieve it from table it printing multiple time. I have tried the following code - please help me what's wrong with the code? (if I remove the drop down which is available below the heading it is printing single time in the table)
<?php
include("session.php");
?>
<?php
include("../view/common/head.php");
?>
<?php
include('../view/common/tab.php');
?>
<body class="bg-color">
<div class="container">
<h1> List Of Courses</h1>
<br/>
<?php
if (isset($_SESSION['message1']))
{
echo $_SESSION['message1'];
unset($_SESSION['message1']);
}
?>
<?php
if (isset($_SESSION['courseupdated']))
{
echo $_SESSION['courseupdated'];
unset($_SESSION['courseupdated']);
}
?>
<?php
if (isset($_SESSION['deletecourse']))
{
echo $_SESSION['deletecourse'];
unset($_SESSION['deletecourse']);
}
?>
<?php
if (isset($_SESSION['notdelete']))
{
echo $_SESSION['notdelete'];
unset($_SESSION['notdelete']);
}
?> <div class="col-md-6 form-group">
<select class="form-control">
<?php
include('../model/functions.php');
$table="courses";
$condition="";
$drop=Selectdata($table,$condition);
foreach($selectarray as $drop)
{
echo '<option value="'.$drop['course_id'].'">'.$drop['course_name'].'</option>';
}
?>
</select>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th>Sno</th>
<th>Course Name</th>
<th>Course Description</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$per_page=5;
if (isset($_GET['page'])) {
$page = $_GET['page'];
}
else {
$page=1;
}
$table="courses";
$per_page=5;
$start_from = ($page-1) * $per_page;
$condition="limit ".$start_from.",".$per_page." ";
$limit=Selectdata($table,$condition);
if($rowcount==0)
{
echo "no records found";
}
else
{
$sno=($page-1) * $per_page;
foreach($selectarray as $course){
$sno++;
echo '<tr>';
echo '<td>'.$sno.'</td>';
echo '<td>'.$course['course_name'].'</td>';
echo '<td>'.$course['course_description'].'</td>';
echo '<td><button type="submit">edit</button><button Onclick="return ConfirmDelete();" type="submit">Delete</button></td>';
echo '</tr>';
}
}
?>
</tbody>
</table>
Click here to add new course
<br/>
<br/>
Toggle Menu
</div>
<?php
$table = "courses";
$condition=" ";
$select=Selectdata($table,$condition);
$total_records = $rowcount;
$total_pages = ceil($total_records / $per_page);
echo '<div class="text-center">';
echo '<ul class="pagination">';
echo "<li><a href='courselist.php?page=1'>".'<<'.'</a></li>';
for ($i=1; $i<=$total_pages; $i++) {
echo "<li><a href='courselist.php?page=".$i."'>".$i.'</a></li>';
}
echo "<li><a href='courselist.php?page=$total_pages'>".'>>'.'</a></li>';
echo "</ul>";
echo '</div>';
?>
<?php
include("../view/common/footer.php");
?>
functions.php
function Selectdata($table,$condition="")
{
global $conn,$result,$selectarray,$rowcount;
$sql="SELECT * from ".$table." ".$condition." ";
$result=$conn->query($sql);
$rowcount=$result->num_rows;
while($row=$result->fetch_assoc())
{
$selectarray[]=$row;
}
return $result;
}
I hope this code is not intended to be used in a real project.
Just add
$selectarray = array();
before
while
in Selectdata function definition.
What happens is that each time you call that function it just amends the full rowset to the same array as it is global.
Try this :
foreach($selectarray as $row)
{
echo '<option value="'.$row['course_id'].'">'.$row['course_name'].'</option>';
}
I have made a script for Pagination and it can be displayed.
I will be a problem when the Next Button is pressed, the Pagination can't continue to the next page.
when the url has changed but the page remains in the first place.
eg:
[1]. http:// localhost /pagination/
This works and can display data 1-10 on page 1.
[2] http:// localhost /pagination/?page=2
paging should've been on page 2, but the data shown is 1-10 (supposedly 11-20)
This is the code:
// data_students.php
<?php
require 'conn.php';
open_conn();
?>
<table class="table table-condensed table-bordered table-hover" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th style="width:20px">No</th>
<th style="width:120px">NIM</th>
<th style="width:200px">Name</th>
<th>Address</th>
<th style="width:120px">Room</th>
<th style="width:120px">Status</th>
<th style="width:40px"></th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
$num_pages = 10;
$num_data = mysql_num_rows(mysql_query("SELECT * FROM students"));
$total_page = ceil($num_data / $num_pages);
// query searching
if(isset($_POST['search'])) {
$key = $_POST['search'];
echo "<strong>Search results for keyword: $key</strong>";
$query = mysql_query("
SELECT * FROM students
WHERE nim LIKE '%$key%'
OR name LIKE '%$key%'
OR address LIKE '%$key%'
OR room LIKE '%$key%'
OR status LIKE '%$key%'
");
// query if the specified page number
} elseif(isset($_GET['page']) && $_GET['page']!="") {
$page = $_GET['page'];
$i = ($page - 1) * $num_pages + 1;
$query = mysql_query("SELECT * FROM students ORDER BY name ASC LIMIT ".(($page - 1) * $num_pages).", $num_pages");
// query when there is no parameter page and search
} else {
$query = mysql_query("SELECT * FROM students ORDER BY name ASC LIMIT 0, $num_pages");
}
// show database students
while($data = mysql_fetch_array($query)) {
if($data['status']==1) {
$status = "Active";
} else {
$status = "Off";
}
?>
<tr>
<td><?php echo $i ?></td>
<td><?php echo $data['nim'] ?></td>
<td><?php echo $data['name'] ?></td>
<td><?php echo $data['address'] ?></td>
<td><?php echo $data['room'] ?></td>
<td><?php echo $status ?></td>
<td>
<a href="#dialog-students" id="<?php echo $data['kd_mhs'] ?>" class="change" data-toggle="modal">
<i class="icon-pencil"></i>
</a>
<a href="#" id="<?php echo $data['kd_mhs'] ?>" class="delete">
<i class="icon-trash"></i>
</a>
</td>
</tr>
<?php
$i++;
}
?>
</tbody>
</table>
<?php if(!isset($_POST['search'])) { ?>
<!-- to display the menu page -->
<div class="pagination pagination-right">
<ul>
<?php for($i = 1; $i <= $total_page; $i++) { ?>
<li class="page" id="<?php echo $i ?>"><?php echo ''.$i.'' ;?></li>
<?php } ?>
</ul>
</div>
<?php } ?>
<?php
close_conn();
?>
this is jquery:
// students-app.js
(function($) {
// function is executed after the entire document is displayed
$(document).ready(function(e) {
var kd_mhs = 0;
var main = "data_students.php";
// show data students from data_students.php in index.php <div id="data-students"></div>
$("#data-students").load(main);
// when the search inputbox filled
$('input:text[name=searching]').on('input',function(e){
var v_search = $('input:text[name=searching]').val();
if(v_search!="") {
$.post(main, {search: v_search} ,function(data) {
$("#data-students").html(data).show();
});
} else {
$("#data-students").load(main);
}
});
// when the button page is pressed
$('.page').live("click", function(event){
// take the value of the inputbox
kd_page = this.id;
$.post(main, {page: kd_page} ,function(data) {
$("#data-students").html(data).show();
});
});
});
}) (jQuery);