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.
Related
I want to update my tbl_category. But when I click on the Update button, it does not show any error. But it does not update the value of tbl_category. I am sure it's very simple since I am a beginner i am not getting well what is wrong exactly so please help me.
Here is the script:
catlist.php
<?php include 'inc/header.php';?>
<?php include 'inc/sidebar.php';?>
<?php include("../classes/Category.php");?>
<?php
$cat = new Category();
if(isset($_GET['delcat'])){
$id = $_GET['delcat'];
//$id = preg_replace('/[^-a-zA-Z0-9_]/', '', $_GET['delcat']);
$delCat = $cat->delCatById($id);
}
?>
<div class="grid_10">
<div class="box round first grid">
<h2>Category List</h2>
<div class="block">
<?php
if(isset($delCat)){
echo $delCat;
}
?>
<table class="data display datatable" id="example">
<thead>
<tr>
<th>Serial No.</th>
<th>Category Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$getCat = $cat->getAllCat();
if($getCat){
$i = 0;
while($result = $getCat->fetch_assoc()){
$i++;
?>
<tr class="odd gradeX">
<td><?php echo $i;?></td>
<td><?php echo $result['catName'];?></td>
<td>Edit || <a onclick="return confirm('Are you sure to delete!')" href="?delcat=<?php echo $result['catId'];?>">Delete</a></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
setupLeftMenu();
$('.datatable').dataTable();
setSidebarHeight();
});
</script>
<?php include 'inc/footer.php';?>
catedit.php
<?php include 'inc/header.php';?>
<?php include 'inc/sidebar.php';?>
<?php include("../classes/Category.php");?>
<?php
/*if(!isset($_GET['catid']) || $_GET['catid'] == NULL){
//echo "<script>window.location = 'catlist.php'; </script>";
} else{
$id = $_GET['catid'];
}*/
$id = isset($_GET['catid']) ? $_GET['catid'] : '';
//$id = $_GET['catid'];
$cat = new Category();
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$catName = $_POST['catName'];
$updateCat = $cat->catUpdate($catName,$id);
}
?>
<div class="grid_10">
<div class="box round first grid">
<h2>Update Category</h2>
<div class="block copyblock">
<?php
echo $id;
?>
<?php
if(isset($updateCat)){
echo $updateCat;
}
?>
<?php
$getCat = $cat->getCatById($id);
if($getCat){
while($result = $getCat->fetch_assoc()){
?>
<form action="catedit.php" method="post">
<table class="form">
<tr>
<td>
<input type="text" name="catName" value="<?php echo $result['catName'];?>" placeholder="Enter Category Name..." class="medium" />
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" Value="Update" />
</td>
</tr>
</table>
</form>
<?php
}
}
?>
</div>
</div>
</div>
<?php include 'inc/footer.php';?>
Category.php
<?php
include_once("../lib/Database.php");
include_once("../helpers/Format.php");
?>
<?php
class Category {
private $db;
private $fm;
public function __construct() {
$this->db = new Database();
$this->fm = new Format();
}
public function catInsert($catName){
$catName = $this->fm->validation($catName);
$catName = mysqli_real_escape_string($this->db->link , $catName);
if(empty($catName)){
$msg = "<span class='error'>Category field must not be empty !</span>";
return $msg;
} else{
$query = "INSERT INTO tbl_category(catName) VALUES('$catName')";
$catinsert = $this->db->insert($query);
if($catinsert){
$msg = "<span class='success'>Category Inserted Successfully</span>";
return $msg;
} else {
$msg = "<span class='error'>Category Not Inserted.</span>";
return $msg;
}
}
}
public function getAllCat(){
$query = "SELECT * FROM tbl_category ORDER BY catId DESC";
$result = $this->db->select($query);
return $result;
}
public function getCatById($id){
$query = "SELECT * FROM tbl_category WHERE catId = '$id'";
$result = $this->db->select($query);
return $result;
}
public function catUpdate($catName,$id){
$catName = $this->fm->validation($catName);
$catName = mysqli_real_escape_string($this->db->link , $catName);
$id = mysqli_real_escape_string($this->db->link , $id);
if(empty($catName)){
$msg = "<span class='error'>Category field must not be empty !</span>";
return $msg;
} else{
//$query = "UPDATE tbl_category
//SET
//catName = '$catName'
//WHERE catId = '$id'";
$query = "UPDATE tbl_category SET catName = '$catName' WHERE catId = '$id'";
$updated_row = $this->db->update($query);
if($updated_row){
$msg = "<span class='success'>Category Updated Successfully</span>";
return $msg;
} else {
$msg = "<span class='error'>Category Not Updated.</span>";
return $msg;
}
}
}
public function delCatById($id){
$query = "DELETE FROM tbl_category WHERE catId = '$id'";
$delData = $this->db->delete($query);
if($delData){
$msg = "<span class='success'>Category Deleted Successfully</span>";
return $msg;
}
else {
$msg = "<span class='error'>Category Not Deleted.</span>";
return $msg;
}
}
}
?>
Once your catedit.php form is submitted, PHP is not receiving 'id', which it needs to be able to execute catUpdate method.
You should have additional (hidden) field in your form which would be for $id. Then, you will take that one from POST as well. $_POST['id'];
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$catName = $_POST['catName'];
$id = $_POST['id'];
$updateCat = $cat->catUpdate($catName,$id);
}
....
<form action="catedit.php" method="post">
<input type="hidden" id="i" name="id" value="<?php echo $id; ?>">
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>
I have a project that I'm doing now and my project consist of CRUD functions and it works fine. My project also has its pagination and search function.
The pagination is working but the search function does not seem to work. What I want is, a search where I can search anything within my table like I want to search all the fields or maybe a live search. Can somebody please help me.
Dbconfig.php
<?php
$db_host = 'localhost'
$db_username = 'root';
$db_password = '';
$db_name = 'survey';
try{
$db_con = new PDO("mysql:host={$db_host};dbname={$dbname}",db_username,$db_password);
}
catch(PDOException $exception{
echo $exception->getMessage();
}
include_once 'class.paginate.php'
$paginate = new paginate($DB_con);
?>
Class.paging.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>
<!-- <td>visit</td> -->
</tr>
<?php
}
}
else
{
?>
<tr>
<td>Nothing here...</td>
</tr>
<?php
}
}
public function search($query)
{
$stmt=$this->db->prepare($query);
$query = '%' . $query . '%';
$stmt->bindparam('query', $query, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_OBJ);
if(empty($result) or $result == false)
return array();
else
return $result;
}
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
}
}
}
Index.php
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="Bootstrap/bootstrap.css">
<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
<body>
<div id="search-wrapper">
<form name="search" method="GET" action="">
<table id="search" class="table-responsive">
<tr>
<input name="var1" type="text" id="search-box">
<button id="submit" name="submit" type="submit">Search</button>
</tr>
</table>
<?php
$query = "SELECT * FROM `login` WHERE (`username` like :query or `password` like :query) ";
$paginate->search($query)
?>
</form>
</div>
<div id="table-wrapper" class="table-responsive">
<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>
<?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);
?>
</table>
</div>
<div id="footer">
cleartuts.blogspot.com
</div>
</body>
</html>
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>
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.