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>
Related
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.';
}
}
?>
i'm working on a website an i have a page showing all the data from my database with pagination all are working fine except for search.when i search like tom it only shows the result from the first page..i have a name of tom in different pages but it only show result where i'm in the current page.
please help me with this..
class.user.php
<?php
class paginate
{
private $db;
function __construct($DB_con)
{
$this->db = $DB_con;
}
public function dataview($query)
{
$stmt = $this->db->prepare($query);
$stmt->execute();
if($stmt->rowCount()>0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['user_id']; ?></td>
<td><?php echo $row['username']; ?></td>
<td><?php echo $row['password']; ?></td>
<td><?php echo $row['province']; ?></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td>Nothing here...</td>
</tr>
<?php
}
}
public function paging($query,$records_per_page)
{
$starting_position=0;
if(isset($_GET["page_no"]))
{
$starting_position=($_GET["page_no"]-1)*$records_per_page;
}
$query2=$query." limit $starting_position,$records_per_page";
return $query2;
}
public function paginglink($query,$records_per_page)
{
$self = $_SERVER['PHP_SELF'];
$stmt = $this->db->prepare($query);
$stmt->execute();
$total_no_of_records = $stmt->rowCount();
if($total_no_of_records > 0)
{
?><tr><td colspan="4" align="center"><?php
$total_no_of_pages=ceil($total_no_of_records/$records_per_page);
$current_page=1;
if(isset($_GET["page_no"]))
{
$current_page=$_GET["page_no"];
}
if($current_page!=1)
{
$previous =$current_page-1;
echo "<a href='".$self."?page_no=1'>First</a> ";
echo "<a href='".$self."?page_no=".$previous."'>Previous</a> ";
}
for($i=1;$i<=$total_no_of_pages;$i++)
{
if($i==$current_page)
{
echo "<strong><a href='".$self."?page_no=".$i."' style='color:red;text-decoration:none'>".$i."</a></strong> ";
}
else
{
echo "<a href='".$self."?page_no=".$i."'>".$i." </a> ";
}
}
if($current_page!=$total_no_of_pages)
{
$next=$current_page+1;
echo "<a href='".$self."?page_no=".$next."'>Next</a> ";
echo "<a href='".$self."?page_no=".$total_no_of_pages."'>Last</a> ";
}
?></td></tr><?php
}
}
}
jquery/ajax
<script>
$(document).ready(function(){
$("#searchme").keyup(function(){
if( $(this).val() != "")
{
$("#data tbody>tr").hide();
$("#data td:contains-ci('" + $(this).val() + "')").parent("tr").show();
}
else
{
$("#data tbody>tr").show();
}
});
});
</script>
index.php
<body>
<div id="table-wrapper" class="table-responsive">
<input type="text" name="search" id="searchme" placeholder="Search...">
<table id="data" class="table table-striped table-hover">
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Password</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM login";
$records_per_page=20;
$newquery = $paginate->paging($query,$records_per_page);
$paginate->dataview($newquery);
$paginate->paginglink($query,$records_per_page);
?>
</tbody>
</table>
</div>
</body>
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 am creating a component for teachers where in teacher can generate pdf for all the students who have completed the course.
Checking all the students and pdfs should be generated and saved on disk. After which a download link is provided to download the zip of all the pdfs generated. This is what i want to achieve. I am using fpdf for generating pdf.
Any suggestions ?
Below is the form that is posted and students id-
<form
action="<?php echo JRoute::_('index.php?option=com_mentor&view=download_certificate&cid=' . $cid . '&Itemid=529') ?>"
name="download_certificate" method="post" id="download_certificate">
<table class="adminlist" border="1" cellpadding="0" cellspacing="0"
style="table-layout: fixed" id="content">
<thead>
<tr>
<th class="nowrap" style="width: 35px">
<input type="checkbox" name="selectall" id="selectall">
</th>
<th class="nowrap" align="center">
<?php echo JText::_('COM_MENTOR_USER_NAME'); ?>
</th>
<th class="nowrap" style="width: 140px">
<?php echo JText::_('COM_MENTOR_COURSE_STATUS'); ?>
</th>
<th class="nowrap" style="width: 140px">
<?php echo JText::_('COM_MENTOR_ENROLLMENT_DATE'); ?>
</th>
<th class="nowrap" style="width: 140px">
<?php echo JText::_('COM_MENTOR_ACTIVITY'); ?>
</th>
<th class="nowrap" style="width: 50px">
<?php echo JText::_('COM_MENTOR_SCORE'); ?>
</th>
<th class="nowrap" style="width: 50px">
<?php echo JText::_('COM_MENTOR_RESULT'); ?>
</th>
</tr>
</thead>
<tbody>
<?php
//echo '<pre>';print_r($this->mentor_details); die;
foreach ($this->mentor_details as $students) {
$cid = $this->mentor_details['cid'];
$i = 1;
foreach ($students['students'] as $student) {
$userid = $student['id'];
// echo '<pre>';
// print_r($student);
// die;
?>
<tr class="status" id="<?php echo $userid ?>">
<td align="center">
<input type="checkbox" id="<?php echo $userid ?>" name="check[]" class="checkbox1"
value="<?php echo $userid ?>">
</td>
<td>
<a href="<?php echo JRoute::_('index.php?option=com_mentor&view=grader&cid=' . $cid . '&uid='
. $userid . $itemid) ?>">
<?php echo $student['username']; ?>
</a>
</td>
<!-- <td>
<?php// echo $student['email']; ?>
</td> -->
<td align="center">
<?php
$incomplete = $completed = $not_started = 0;
for ($k = 0; $k < count($student['elements']); $k++) {
foreach ($student['elements'] as $elements) {
if ($elements['userid'] == $userid) {
// echo '<pre>';print_r($elements); die;
if ($elements['element']['cmi.core.lesson_status'] == 'incomplete') {
$incomplete++;
} else {
$completed++;
}
}
}
}
if ($incomplete == 0 && $completed == 0) {
echo 'Not yet started';
} else {
if ($completed == count($student['elements'])) {
echo 'Completed';
} else {
echo 'Incomplete';
}
}
?>
</td>
<td align="center">
<?php
if (!empty($student['timestart'])) {
$date = date('d-m-Y H:i', $student['timestart']);
echo $date;
} else {
echo "Not yet started";
} ?>
</td>
<td align="center">
<?php
if (!empty($student['activity']['lasttime']) && (!empty($student['activity']['starttime']))) {
$start_date = date('d-m-Y H:i', $student['activity']['starttime']);
$last_date = date('d-m-Y H:i', $student['activity']['lasttime']);
echo $start_date . '<br/>' . $last_date;
} else {
echo "-";
} ?>
</td>
<td align="center">
<?php
$grades = $student['grades'];
$total_grade = array();
$j = 0;
//for ($j = 0; $j < count($grades); $j++) {
// $total_grade[$j] = $grades[$j]['finalgrade'];
//}
//print_r($total_grade);die;
if (!empty($grades)) {
//echo number_format(array_sum($total_grade), 2);
$total_grade[$j] = $grades[$j]['finalgrade'];
echo number_format($total_grade[$j], 2);
} else {
echo '-';
}
//echo '<pre>';
//print_r($student['grades']);
//die;
?>
</td>
<td align="center">
<?php
//echo '<pre>';print_r($student);die;
if (!empty($student['scores'])) {
if (isset($grades[$j]['feedbacktext'])) {
echo $grades[$j]['feedbacktext'];
} else {
echo '-';
}
} else {
echo '-';
}
?>
</td>
</tr>
<?php $i++;
}
} ?>
</tbody>
</table>
</form>
<script>
function checked_value() {
var checkedValue = [];
var $len = $(".checkbox1:checked").length;
if ($len == 0) {
alert('Please select user');
}
// else if ($len > 1) {
// alert('Please select a single user only.');
// }
else {
$(".checkbox1").each(function () {
var $this = $(this);
if ($this.is(":checked")) {
checkedValue.push($this.attr("id"));
}
});
$("#download_certificate").submit();
</script>
On Clicking image tag, form is submitted with the students id and I am getting students data, his name, grades, course,
<img src="/components/com_mentor/images/certificate_blue.png" class="certificate-ico right"
title="Download Certificate" onclick="checked_value();"/>
After this processing, page is redirected to pdf.php page
require_once('/wamp/opt/bitnami/apache2/htdocs/lms/lib/fpdf/fpdf.php');
$pdf = new FPDF(); $pdf->SetFont('times', '', 12);
$pdf->SetTextColor(50, 60, 100); $pdf->AddPage('L');
$pdf->SetDisplayMode(real, 'default'); $pdf->SetXY(10, 60);
$pdf->SetFontSize(12);
$pdf->Write(5, 'Dear Ms.XYX');
$filename = "test.pdf";
$dir = "/assets/";
$pdf->Output($dir . $filename, 'F');
Thanks guys for your help.. Solved my question.
Looped through the pdf function for n no. of users.
i have these three files:
index.php:
<div class="tweet_bx">
<form method="post" name="m_gigs" id="m_gigs" enctype="multipart/form-data" action="index.php">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="17%"><strong>Filter gigs by</strong></td>
<td class="<?php echo $class1; ?>" width="8%" align="center" ><a class="cuuuent" href="index.php?gigs=latest" >Latest</a></td>
<td class="<?php echo $class2; ?>" width="15%" align="center">Most Popular</td>
<td class="<?php echo $class3; ?>" width="15%" align="center"><a href="index.php?gigs=rating" >Best Ratings</a></td>
</tr>
</table>
<table>
<?php
include('Sql.php');
$c = new connexion();
$videos= $c->getVideos();
for($i=0;$i<sizeof($videos); $i++)
{
?>
<tr><td colspan = "2"><img src="<?php echo $videos[$i]['image']; ?> " /></td>
<td><label color="blue"><?php echo $videos[$i]['titre']; ?></label></td>
</tr>
<tr>
<td><label color="blue"><?php echo $videos[$i]['description']; ?></label></td>
</tr>
<?php
}
?>
</table>
</form>
</div>
<div class="tweet_bx">
<?php
?>
</div>
</div>
<?php include('right.php'); ?>
</div>
the file right.php:
<div class="right_box">
<div class="right_box_center">
<ul>
<?php
include('Sql.php');
$c = new connexion();
$categories = $c->getCategories();
for($i=0;$i<sizeof($categories) ; $i++){
?>
<li><?php echo $categories[$i]['categorie'];?> </li>
<?php
}
?>
</ul>
</div>
<img align="middle" src="images/img.jpg" />
<img align="middle" src="images/invite.jpg" style="padding-left:32px;" />
</div>
and finally the file sql.php:
<?php
class connexion {
function __construct(){
$HOST_DB ="mysql11.000webhost.com";
$NAME_DB="a1638637_fiverr";
$USER_DB ="a1638637_afif";
$PWD_DB="azerty2012";
$connect = mysql_connect($HOST_DB,$USER_DB,$PWD_DB) or die();
$db=mysql_select_db($NAME_DB);
}
//Registration part
function register($email,$login,$pass){
$verif_email= $this->exists($email,0);
$verif_user = $this->exists($user,1);
if(!$verif_email && !$verif_user){
$requete_insert_tem ="INSERT INTO member (`email`,`user`,`password`) VALUES ('".$email."', '".$login."','".$pass."'); ";
mysql_query($requete_insert_tem) or die();
return true;
}
else return false;
}
function exists($attribut,$number){
if($number==0){
$Log_query=mysql_query("SELECT * FROM member WHERE email ='$attribut'") or die(mysql_error());
if ($Log_query == true && mysql_num_rows($Log_query) >0)return true;
else return false;
}
if($number==1){
$Log_query=mysql_query("SELECT * FROM member WHERE user ='$attribut'") or die(mysql_error());
if ($Log_query == true && mysql_num_rows($Log_query) >0)return true;
else return false;
}
}
//login part
function login($attr, $pass){
$verif_email= $this->exists($attr,0);
$verif_user = $this->exists($attr,1);
if($verif_email){
$Log_query=mysql_query("SELECT * FROM member WHERE email ='$attr' AND password = '$pass'") or die(mysql_error());
if ($Log_query == true && mysql_num_rows($Log_query) >0) {
$p=0;
while ($Res_user = mysql_fetch_array($Log_query) ) {
$marques[$p] = $Res_user;
$p++;
}
}
return $marques;
}
if($verif_user){
$Log_query=mysql_query("SELECT * FROM member WHERE user ='$attr' AND password = '$pass'") or die(mysql_error());
if ($Log_query == true && mysql_num_rows($Log_query) >0) {
$p=0;
while ($Res_user = mysql_fetch_array($Log_query) ) {
$marques[$p] = $Res_user;
$p++;
}
}
return $marques;
}
return null;
}
function getCategories(){
$Log_query=mysql_query("SELECT distinct(categorie) FROM video ") ;
if ($Log_query == true && mysql_num_rows($Log_query) >0) {
$p=0;
while ($Res_user = mysql_fetch_array($Log_query) ) {
$marques[$p] = $Res_user;
$p++;
}
}
return $marques;
}
function getVideos(){
$Log_query=mysql_query("SELECT * FROM video ") ;
if ($Log_query == true && mysql_num_rows($Log_query) >0) {
$p=0;
while ($Res_user = mysql_fetch_array($Log_query) ) {
$marques[$p] = $Res_user;
$p++;
}
}
return $marques;
}
}
?>
i have this error : Fatal error: Cannot redeclare class connexion in /home/a1638637/public_html/Sql.php on line 2 . but i didn't redeclare the class connexion!!
i think that the problem is in the right.php file because:
the right part doesn't work
the error appears there
to fix this error i need to know
what is the error?
how can i fix it?
You need to use require_once instead of include. The SQl.php file is read and parsed twice and therefore it tries to redeclare an already declared class. With require_once this won't happen.