How to convert integer data from database to string in php codeigniter - php

In database ,The 'status' column includes values 1(Active users) and 0 (Deactive users), But in my view I would like to show this data as string "Active" and "Deactive". below is my code , the problem is it returns all users status "Deactive" in view. i would appreciate any help and guidance
Here is controller
function index()
{
$data['staff'] = $this->staff_model->getStaffDetails();
$data['status'] = $this->staff_model->getStatus();
// print_r($data);
// die;
$this->load->view('admin/staff/index',$data);
}
Here is Model
function getStatus()
{
$query = $this->db->get_where('user_login',array('status' ))->result();
return $query;
}
And here is the view
<tbody>
<?php
foreach($staff as $n)
{
?>
<tr>
<td><?php echo $n->first_name;?></td>
<td><?php echo $n->email;?></td>
<td><?php echo $n->mobile_no;?></td>
<td><?php echo $n->role;?></td>
<td><?php echo $n->company_name;?></td>
<!-- <td><span class="icoact"></span> <?php echo $n->status;?></td> -->
<td><span class="icoact"></span>
<?php
// foreach($status as $n)
{
if('status' == 1)
{
echo "Active";
}elseif('status' == 0)
{
echo "Deactive";
}
};?>
</td>
<td><a class="edit" href="<?php echo site_url('staff_edit/'.$n->id);?>"><i class="fa fa-pencil-square-o"></i></a>&nbsp
<a class="delete" href="<?php echo site_url ('staff_delete/'.$n->id);?>" onclick="return confirm('Are you sure want to Delete this Record?')"><i class="fa fa-trash-o"></i></a>&nbsp</td>
</tr>
<?php
}
?>
</tbody>

use this in your view:-
<?php
{
if($n->status==1){
echo $status = "Active users";
} else if($n->status==0){
echo $status = "Deactive users";
}
}?>

Related

How to show same id data in single row in codeigniter?

public function get_orderProduct($loginuserID) {
$this->db->select('client_order.*,product.image_gallery,product.name');
$this->db->from('client_order');
$this->db->join('product','client_order.productID = product.productID','LEFT');
$this->db->where('client_order.clientID',$loginuserID);
$this->db->where('client_order.status',1);
$this->db->order_by('client_order.id','desc');
$sql = $this->db->get();
$result = $sql->result();
return $result;
}
<?php
if(count($result) > 0){
$i=1;
foreach($result as $row){
$img = explode(",", $row->image_gallery);
?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $row->orderID; ?></td>
<td><?php echo $row->name; ?></td>
</tr>
<?php
$i++;
}
}else{
?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
No order available!
</div>
<?php
}
?>
I have two product with same orderID and I want to show same orderID product in single row. Now, Here it show in different different row. So, How can I show in single row? Please help me.
Thank You
To solve this, you have to create an empty array to store orderids.Before you print the orderid you have to search the array using in_array method, if orderid exists ignore printing it, otherwise print and push the orderID to the array using array_push method.
<?php
$ids = array();
$i=1;
foreach($result as $row){
$img = explode(",", $row->image_gallery);
?>
<tr>
<td><?php echo $i; ?></td>
<td>
<?php
if(!in_array($row->orderID,$ids))
{
echo $row->orderID;
array_push($ids,$row->orderID);
}
?>
</td>
<td><?php echo $row->name; ?></td>
</tr>
<?php
$i++;
}
?>

I need to use the data on another page

I want to load another view using the function within the same controller. I'm new to codeIgniter so Please go easy on me :D
loaded home page by default -> From Home page filled in fields -> submit -> using ajax grabbed data from database -> use data on another page by loading the new view in the same controller as the default.
Controller:
<?php
class logInCon extends CI_Controller
{
public function login()
{
//$data['creds'] = $this->accsModel->getUser();
$this->load->view("Login");
}
public function validate_LogIn()
{
$uname = $this->input->post('uname');
$pass = $this->input->post('pass');
$this->load->model("accsModel");
$data = $this->accsModel->logInCheck($uname, $pass);
$check = $data['verified'];
if ($check <= 0)
{
echo "Not a valid member";
}else
{
$data['logged'] = $this->accsModel->getUser($uname, $pass);
$this->load->view('comms.php');//want this to load
}
}
}
?>
Model
<?php
/**
*/
class accsModel extends CI_Model
{
public function getBps()
{
$query = $this->db->get('bps');
return $query->result();
}
public function getUser($uname, $psswrd)
{
$getCreds = $this->db->query("SELECT `bps`.*, `users`.bps_id
FROM `bps`
LEFT JOIN `users`
ON `bps`.id = `users`.bps_id
AND `users`.`uname` = '$uname'
AND `users`.`pwd` ='$psswrd'
WHERE `users`.bps_id != ''
OR `users`.bps_id IS NOT NULL");
return $getCreds->result();
}
public function logInCheck($uname, $psswrd)
{
$this->db->select('COUNT(*) AS verified');
$this->db->where('uname', $uname);
$this->db->where('pwd', $psswrd);
$this->db->limit(1);
return $this->db->get('users')->row_array();
}
}
?>
View
<body>
<div class="container">
<div class="row">
<div class="LogForm">
<div class="col-md-12">
<input type="text" id="bpCode" name="bpCode">
</div>
<div class="col-md-12">
<input type="password" id="pass" name="pass">
</div>
<div class="btn">
<span id="emptyF" hidden style="color:red;"></span>
<button id="submit" class="btn btn-info btn-lg btn-block">Login</button>
<span id="result"></span>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function()
{
$("#submit").click(function()
{
var uname = $('#bpCode').val();
var pass = $('#pass').val();
if(uname == "" || pass =="")
{
$("#emptyF").attr("hidden", false).html("Please fill in the form");
}else{
$("#emptyF").attr("hidden", true);
$.ajax({//start of ajax function
type: "POST",
url: "<?php echo base_url('logInCon/validate_LogIn'); ?>",
data:
{
uname : uname,
pass : pass
}
//end of ajax function
});
}
});
});
</script>
</body>
View comms want this to be loaded and use the the data from the getUser() function
<body>
<p><?php print_r($logged) ?></p>
<h1>Commissions View</h1>
<table style="width:100%">
<?php
foreach ($logged as $lgdIn) {
?>
<tr>
<th>ID</th>
<th>bpID</th>
<th>pc</th>
<th>up</th>
<th>tmLdr</th>
<th>fName</th>
<th>mName</th>
<th>lName</th>
<th>contactNo</th>
<th>Status-Id</th>
<th>bpclass_id</th>
</tr>
<tr>
<td><?php echo $lgdIn->id; ?></td>
<td><?php echo $lgdIn->bpID; ?></td>
<td><?php echo $lgdIn->pc; ?></td>
<td><?php echo $lgdIn->up; ?></td>
<td><?php echo $lgdIn->tmLdr; ?></td>
<td><?php echo $lgdIn->fName; ?></td>
<td><?php echo $lgdIn->mName; ?></td>
<td><?php echo $lgdIn->lName; ?></td>
<td><?php echo $lgdIn->contactNo; ?></td>
<td><?php echo $lgdIn->status_id; ?></td>
<td><?php echo $lgdIn->bpclass_id; ?></td>
</tr>
<?php
}
?>
</table>
</body>
You need to pass $data in load view just like below code
public function validate_LogIn()
{
$uname = $this->input->post('uname');
$pass = $this->input->post('pass');
$this->load->model("accsModel");
$data = $this->accsModel->logInCheck($uname, $pass);
$check = $data['verified'];
if ($check <= 0)
{
echo "Not a valid member";
}else{
$data['logged'] = $this->accsModel->getUser($uname, $pass);
$this->load->view('comms',$data);//want this to load
}
}
little change in view too
<body>
<p><?php print_r($logged) ?></p>
<h1>Commissions View</h1>
<table style="width:100%">
<tr>
<th>ID</th>
<th>bpID</th>
<th>pc</th>
<th>up</th>
<th>tmLdr</th>
<th>fName</th>
<th>mName</th>
<th>lName</th>
<th>contactNo</th>
<th>Status-Id</th>
<th>bpclass_id</th>
</tr>
<?php if(!empty($logged)) { foreach ($logged as $lgdIn) { ?>
<tr>
<td><?php echo $lgdIn->id; ?></td>
<td><?php echo $lgdIn->bpID; ?></td>
<td><?php echo $lgdIn->pc; ?></td>
<td><?php echo $lgdIn->up; ?></td>
<td><?php echo $lgdIn->tmLdr; ?></td>
<td><?php echo $lgdIn->fName; ?></td>
<td><?php echo $lgdIn->mName; ?></td>
<td><?php echo $lgdIn->lName; ?></td>
<td><?php echo $lgdIn->contactNo; ?></td>
<td><?php echo $lgdIn->status_id; ?></td>
<td><?php echo $lgdIn->bpclass_id; ?></td>
</tr>
<?php } } else { ?>
<tr colspan="11"><td>No record found.</td></tr>
<?php } ?>
</table>
</body>

Codeigniter and mysql - all data displayinging

I am new in codeigniter and php.I made an uploading system.After uploading the file by user, i just want to display the user uploaded file.But Following code is displaying all the data of the mysql.How can user see only his uploaded data?Can someone suggest replacement
<?php
if (!empty($list) > 0) {
foreach ($list as $row) {
?>
<table class="table table-hover">
<tr>
<th>Manuscript ID</th>
<th>Journal</th>
<th>Title</th>
<th>Date</th>
<th>Action</th>
</tr>
<?php
if (!empty($list) > 0) {
foreach ($list as $row) {
?>
<tr>
<td><?php echo $row->manu_id; ?></td>
<td><?php echo $row->sub_title; ?></td>
<td><?php echo $row->title; ?></td>
<td><?php echo $row->created_date; ?></td>
<td>
<a href="<?php
echo
site_url('user/removemanuscript/' . base64_encode($row->manu_id));
?>"
title="Soft Delete">Remove
</a>
<?php if ($row->final_status == 1) { ?>
<span class="label label-primary">Approved</span>
<?php } else if ($row->final_status == 2) { ?>
<span class="label label-
danger">Disapproved</span>
<?php } else { ?>
<span class="label label-warning">Pending</span>
<?php } ?>`enter code here`
</td>
</tr>
<?php
}
}
?>
</table>
<?php
}
}
I am adding user controller for uploaded file.Please let me know
public function FinalManuscriptSubmit()
{
if ($this->Common_model->Is_User_Logged())
{
$data=array();
$joinClause=array();
$whereClause=array();
$session_data = $this->session->userdata('user_logged_in');
$u_id = $session_data['id'];
$sql="SELECT u.*,f.manu_id,m.journal_id,m.title,j.sub_title,f.created_date,f.final_status
FROM user u
INNER JOIN final_manuscript f on f.user_id = u.user_id
INNER JOIN manuscript m on m.manu_id = f.manu_id
INNER JOIN journal j on j.sub_id = m.journal_id
";
$data['list']=$this->Common_model->get_data_by_query($sql);
//print_r($data['list']);exit;
$this->load->view('user/header');
$this->load->view('user/showmanu',$data);
$this->load->view('user/footer');
}else{
redirect('user/login');
}
}
I will be thankful for your support.

Codeigniter-how to foreach and echo project name by id in my view page

$data['posts'] = $this->whiteboard_model->u_getTSrowsindex(array('limit'=>$this->perPage));
$data['postsexp'] = $this->whiteboard_model->u_getTSrowsexp(array('limit'=>$this->perPage));
//print_r($data['postsexp']); exit;
foreach($data['posts'] as $post)
{
$project_id =$post['project_name'];
$data['projectName'] = $this->whiteboard_model->get_project_name($project_id);
print_r($data['projectName']);
}
//This is my controller
public function get_project_name($project_id) {
$this->db->select('project_name');
$this->db->from('project_list');
$this->db->where('project_id',$project_id);
$query = $this->db->get();
//echo $this->db->last_query();
//return fetched data
return ($query->num_rows() > 0)?$query->result_array():FALSE;
}
//my model
<?php if(!empty($posts)): foreach($posts as $post):
//print_r($post);?>
<tr>
<td> <?php echo $post['advisor']; ?></td>
<td> <?php echo $post['spentdate']; ?></td>
<td><?php echo $post['project_name']; ?>
<?php if(!empty($projectName)){
foreach($projectName as $prj_name){ //print_r($projectName);
echo $prj_name['project_name'];
}
} ?>
</td>
<td> <?php echo $post['activity']; ?></td>
<td> <?php echo $post['billtype']; ?></td>
<td> <?php echo $post['timespent']; ?></td>
<td> <?php if($post['status'] == 1){?>
<b style = "color:blue;">Pending</b>
<?php }else if($post['status'] == 2){?>
<b style = "color:green;">Approved</b>
<?php }else{?> <b style = "color:red;">Rejected</b>
<?php } ?> </td>
</tr>
<?php endforeach; else: ?>`enter code here`
//my view file
Finally iam not getting proper values from projectName array ..its giving only one name
It seems like you are fetching data using the project_id
$this->db->select('project_name');
$this->db->from('project_list');
$this->db->where('project_id',$project_id);
$query = $this->db->get();
Here you may be getting only the details of one project where the project_id = $project_id
Comment out that line and see if you get all the project names. Additionally use a print_r($query->result()); to verify your data.
So that it would look like:
$this->db->select('project_name');
$this->db->from('project_list');
//$this->db->where('project_id',$project_id);
$query = $this->db->get();
print_r($query->result());
You can refer more here.

Get error "You do not have sufficient permissions to access this page" While creating custom plugin

I have created custom plugin in wordpress for get data from the database. And I have added two link to perfrom action on records .One is Edit and another is Delete. I have written code for delete link like this
Delete
When I click on delete link it will show error like
You do not have sufficient permissions to access this page
My plugin code is
function submit_review()
{
add_options_page("Submit Review","Submit Reviews",1,"submit_review","submit_review");
global $wpdb;
$id = get_current_user_id();
$q = "select * from wp_submit_review where user_id = " . $id;
$result = $wpdb->get_results($q,OBJECT);
if(!empty($result))
{
?>
<div class="wrap">
<h1>Submitted Reviews</h1>
<div style="width: 100%;">
<table cellpadding="5" class="wp-list-table widefat fixed pages">
<thead>
<tr>
<th><b>Review Id</b></th>
<th><b>User Name</b></th>
<th><b>Submitted Category</b></th>
<th><b>New Listing Name</b></th>
<th><b>New Listing Address</b></th>
<th><b>New Listing City</b></th>
<th><b>New Listing Description</b></th>
<th><b>Image</b></th>
<th><b>R-option</b></th>
<th><b>New Listing Rating</b></th>
<th><b>New Listing Review</b></th>
<th><b>Actions</b></th>
</tr>
</thead>
<tbody>
<?php
foreach($result as $res)
{
?>
<td><?php echo $res->review_id; ?></td>
<td><?php echo get_the_author_meta('user_login',$res->user_id); ?></td>
<td><?php
if($res->submit_category == 1)
{
echo "Service";
}
else if($res->submit_category == 2)
{
echo "Restaurant";
}
else
{
echo "Product";
}
?>
</td>
<td><?php echo $res->newlistingname; ?></td>
<td><?php echo $res->newlistingaddress; ?></td>
<td><?php echo $res->newlistingcity; ?></td>
<td><?php echo $res->newlistingdesc; ?></td>
<td><img src="<?php echo home_url()."/uploads/".$res->image; ?>" height="50px" width="50px"/></td>
<td><?php echo $res->roption; ?></td>
<td><?php echo $res->newlistingrating; ?></td>
<td><?php echo $res->newlistingreview; ?></td>
<td>Edit | Delete</td>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<?php
}
else
{
echo "No review find";
}
}
function delete_my_review()
{
echo $_GET['id'];
}
add_action("admin_menu","delete_my_review");
function submit_review_menu()
{
add_menu_page("Submit Review","Submit Review","manage_options","submit_review", submit_review);
}
//add_action("admin_menu","submit_review");
add_action("admin_menu","submit_review_menu");
So how to call delete_my_review() function to perform delete action?
simply create a function with ajax and php. following example worked for me.
html delete button
<td><button onclick="delete_ab(<?php echo $results->id; ?>)">Delete</button></td> // pass your id to delete
javascript function
function delete_ab(str)
{
jQuery.post(
// see tip #1 for how we declare global javascript variables
MyAjax.ajaxurl,
{
// here we declare the parameters to send along with the request
// this means the following action hooks will be fired:
// wp_ajax_nopriv_myajax-submit and wp_ajax_myajax-submit
action : 'myajax_submit',
// other parameters can be added along with "action"
postID : str
},
function(response)
{
document.getElementById(str).style.display='none';
}
);
}
main function in php
function myajax_submit() {
// get the submitted parameters
$postID = $_POST['postID'];
global $wpdb;
$qry=$wpdb->query("DELETE FROM `price_table` WHERE id=$postID");
// generate the response
echo "hello";
// IMPORTANT: don't forget to "exit"
exit;
}

Categories