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.
Related
I have a sql query and I want it to also only show the information for the logged in user. I was thinking is it possible for me to add another where clause to the query to add in: username = '".$_SESSION['login_user']."'
Here is my query:
$sql= "
SELECT
user.username,books.bid,name,authors,edition,
status,approve,issue,issue_book.return
FROM user
inner join issue_book ON user.username=issue_book.username
inner join books ON issue_book.bid=books.bid
WHERE issue_book.approve ='$exp'
ORDER BY `issue_book`.`return` DESC";
Anyone know how I would write this to achieve what I want above?
Here is my entire code:
<!-- Updated navbar for logged in user -->
<?php
if($_SESSION['login_user'])
{
include "navbar_user.php";
}
?>
<h2 style = "text-align: center; padding: 2%;">Your Expired Books </h2>
<?php
if(isset($_SESSION['login_user']))
{
$exp = 'EXPIRED';
$session_value = $_SESSION['login_user'];
$sql= "SELECT user.username,books.bid,name,authors,edition,status,approve,issue,issue_book.return FROM user inner join issue_book
ON user.username=issue_book.username inner join books ON issue_book.bid=books.bid WHERE issue_book.approve ='$exp' AND username = ".$_SESSION['login_user']."
ORDER BY `issue_book`.`return` DESC";
$res = mysqli_query($db,$sql);
if(mysqli_num_rows($res)==0)
{
echo "You have no expired books.";
}
else
{
?>
<table class = 'table table-bordered'>
<tr style='background-color: #abb79b; color: white;'>
<th>Username</th>
<th>BID</th>
<th>Book Name</th>
<th>Authors Name</th>
<th>Edition</th>
<th>Status</th>
<th>Return Date</th>
</tr>
<?php
while ($row = mysqli_fetch_assoc($res)) {
?>
<tr style = 'background-color: white;'>
<td><?php echo $row['username'] ?></td>
<td><?php echo $row['bid'] ?></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['authors'] ?></td>
<td><?php echo $row['edition'] ?></td>
<td><?php echo $row['status'] ?></td>
<td><?php echo $row['return'] ?></td>
</tr>
<?php
}
}
}
else
{
echo "</br></br></br>";
echo "<h2><b>";
echo "Please login first.";
echo "</b></h2>";
}
?>
</table>
use and(&&) operator
It may allow to add as many condition as use want
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> 
<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> </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";
}
}?>
Please help me how can i unlink a image when i delete a product.I dont know where is my error in my code .Thank everyone so much.I tried different way to resolve this problem.I teached myself learn to code on youtube, and then I tried to create another model.Please help me solve this problem.
Html Page
<h3>List Product</h3>
<table id="user">
<thead>
<tr>
<th>Serial</th>
<th>Product Name</th>
<th>Image</th>
<th>Price</th>
<th>Category</th>
<th>Type</th>
<th>Action</th>
</tr>
</thead>
<?php
if(!empty($_GET['msg'])){
$msg = unserialize(urldecode($_GET['msg']));
foreach ($msg as $key => $value){
echo '<span style="color:blue;font-weight:bold">'.$value.'</span>';
}
}
?>
<tbody>
<?php
$i = 0;
foreach($listproduct as $key => $listpro){
$i++;
?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $listpro['productName']; ?></td>
<td><img src="<?php echo BASE_URL ?>/teamplate/image/<?php echo $listpro['image']; ?>" width="60" height="60"></td>
<td><?php echo $listpro['price']; ?></td>
<td><?php echo $listpro['catName'] ?></td>
<td>
<?php
if($listpro['type']==0){
echo 'Feathered';
}else{
echo 'Non-Feathered';
}
?>
</td>
<td>Delete
|| Edit
</td>
</tr>
<?php
}
?>
</tbody>
</table>
Function in Product page
public function delPro($id = NULL){
$tablePro = 'tbl_product';
$this->data = array();
$ProductModel = $this->load->model('ProductModel');
$result = $ProductModel->delProductById($tablePro, $id);
if($result == 1){
$this->data['productbyid'] = $ProductModel->updateProductById($tablePro, $id);
$path_unlink= BASE_URL."/teamplate/image/";
foreach($this->data['productbyid'] as $this->key => $this->value){
$image_pro = $this->value['image'];
unlink($path_unlink.$image_pro);
}
$mdata['msg'] = "Product Deleted Successfully...";
}else{
$mdata['msg'] = "Product Not Deleted...";
}
$url = BASE_URL."/Product/ListProduct?msg=".urlencode(serialize($mdata));
header("Location:$url");
}
ProductModel Page
public function updateProductById($tablePro, $id){
$query = "SELECT * from $tablePro where productId = '$id'";
return $this->db->select($query);
}
I'm confused how
I want to display like this (just click in link)
there's view and database
this my view which I want
Explanation:
If in database I insert in table
npp:87
tgl_masuk:20/02/2009
nama:ulung tgl_mulai:01/01/2015
tgl_pengajuan:03/01/2015
tgl_selesai:08/01/2015
lama:5
bagian:1
this data will display on column bagian=1 and the field value=5
etc
this my view now
<thead>
<tr>
<th>npp</th>
<th>Nama </th>
<th>Tanggal Masuk </th>
<th>Tanggal Mulai</th>
<th>Tanggal Selesai</th>
<th>Lama</th>
<th>Bagian</th>
<th>tanggal Pengajuan</th>
</tr>
</thead>
<tbody>
<?php if(!empty($query)) { foreach($query as $row) { ?>
<tr>
<td style="text-align:center;font-weight:bold">
<span class="label label-warning"><?php echo $row->npp ?></span>
</td>
<td><?php echo $row->nama_pegawai ?></td>
<td><?php echo $row->tgl_masuk ?></td>
<td><?php echo $row->tgl_mulai ?></td>
<td><?php echo $row->tgl_selesai ?></td>
<td><?php echo $row->lama ?></td>
<td><?php echo $row->bagian ?></td>
<td><?php echo $row->tgl_pengajuan ?></td>
</tr>
<?php }} ?>
controller
function index($limit='',$offset=''){
if($this->session->userdata('LOGIN')=='TRUE'){
$this->load->model("Cutitahun_Model");
$data['judul']='Histori Cuti tahun Pegawai';
/* VAGINATION */
if($limit==''){ $limit = 0; $offset=10 ;}
if($limit!=''){ $limit = $limit ; $offset=$this->offset ;}
$data['count']=$this->Cutitahun_Model->countcuti_tahun();
$config['base_url'] = base_url().'Cuti_tahun/search/';
$config['total_rows'] = $data['count'];
$config['per_page'] = $this->limit;
$config['cur_tag_open'] = '<span class="pg">';
$config['cur_tag_close'] = '</span>';
$this->pagination->initialize($config);
/*----------------*/
$data['query']=$this->Cutitahun_Model->getListCuti($limit,$offset);
$data['view']='Cuti_tahun/hist_cuti';
$this->load->view('index',$data);
}else {
redirect('home/loginPage');
}
}
model
function getListCuti($limit='',$offset=''){
$menus='';
$judul=$this->input->post('judul');
$status=$this->session->userdata('STATUS');
$addTag="";
if($status!=0){
$addTag="where t_pegawai.nik='".$this->session->userdata('NIK')."'";
}
$query=$this->db->query("select t_cuti.status as status,t_cuti.id as cutiid,t_pegawai.id,t_pegawai.nik,t_pegawai.nama,m_jabatan.nama_jabatan,m_unit_kerja.nama_unit_kerja,m_cabang.nama_cabang from t_cuti
LEFT JOIN t_pegawai ON t_pegawai.nik=t_cuti.nik
LEFT JOIN m_jabatan ON t_pegawai.kd_jabatan=m_jabatan.kd_jabatan
LEFT JOIN m_unit_kerja ON t_pegawai.kd_unit_kerja=m_unit_kerja.kd_unit_kerja
LEFT JOIN m_cabang ON t_pegawai.kd_cabang=m_cabang.kd_cabang
$addTag
ORDER BY t_cuti.id DESC LIMIT $limit,$offset");
if ($query->num_rows() > 0) {
foreach ($query->result() as $data) {
$menus[]=$data;
}
return $menus;
}
}
How do I make my table dynamically list all the values it pulls from the api, atm it only pulls 1 record and puts it in the table, the rest of the data gets put outside it
Probably something very small I'm missing here, but can't put my finger on it
Thanks for any help, very appreciated.
<?php
$trackingId = $_POST['trackingId'];
if (isset($_POST['trackingId'])) {
$fetch = json_decode(file_get_contents(sprintf('apigoeshere', $trackingId)));
if ($fetch->status != 'OK') {
echo sprintf('Error: %s', $fetch->message);
} else {
//example how to access statistics variable
$inactiveAccounts = $fetch->statistics->inactiveAccounts;
echo sprintf('Inactive accounts: %d' . "<br /><br />", $inactiveAccounts);
?>
<table border="1">
<tr>
<th>Account name</th>
<th>Level</th>
</tr>
<?php
//example how to display all accounts username
foreach ($fetch->accounts as $account) {
?>
<tr>
<td><?php
echo $account->username;
?></td>
<td><?php
echo $account->currentLevel;
?></td>
</tr>
</table>
<?php
}
}
}
?>
Didnt close foreach in right place. use this code instead
<?php
$trackingId = $_POST['trackingId'];
if (isset($_POST['trackingId'])) {
$fetch = json_decode(file_get_contents(sprintf('apigoeshere', $trackingId)));
if ($fetch->status != 'OK') {
echo sprintf('Error: %s', $fetch->message);
} else {
//example how to access statistics variable
$inactiveAccounts = $fetch->statistics->inactiveAccounts;
echo sprintf('Inactive accounts: %d' . "<br /><br />", $inactiveAccounts);
?>
<table border="1">
<tr>
<th>Account name</th>
<th>Level</th>
</tr>
<?php
//example how to display all accounts username
foreach ($fetch->accounts as $account) {
?>
<tr>
<td><?php
echo $account->username;
?></td>
<td><?php
echo $account->currentLevel;
?></td>
</tr>
<?php
}
?>
</table>
<?php
}
}
?>