Active/inactive users using checkbox in codeigniter - php

i need to update my database as soon as i check the checkbox with the value of 0(inactive) and 1(active). if i uncheck the checkbox the user would be unable to access the page means he/she is blocked from user panel. and if i check the box again the user can be enable to access the whole web means he/she would be unblocked.
i wonder if i can do this in codeigniter. i have searched for it but i cannot get them. Advance sorry it there is silly one.
Thankyou for any help.
This is my view file :
<div class="col-main">
<h1 class="page-title">All Users</h1>
<div class="admin_panel">
<ul class="form-fields">
<li class="full-row">
<table class="table demo">
<tr>
<td colspan="3">Add New</td>
</tr>
<tr>
<td colspan="3"><label>Quick Search : </label>
<input id="filter" type="text"/></td>
</tr>
</table>
</li>
</ul>
<table class="table demo table-bordered product_grid" data-filter="#filter">
<thead>
<tr>
<th>S.No</th>
<th>First Name</th>
<th>last Name</th>
<th>Password</th>
<th>Username</th>
<th>Password</th>
<th>Status</th>
<th colspan="2">Action</th>
</tr>
</thead>
<tbody> <tr>
<?php if(isset($pro_data) && $pro_data != false){ ;
foreach ($pro_data as $da) { ?>
<td><?php echo $da['reg_id']; ?></td>
<td><?php echo $da['reg_fname']; ?></td>
<td><?php echo $da['reg_lname']; ?></td>
<td><?php echo $da['reg_pass']; ?></td>
<td><?php echo $da['reg_email']; ?></td>
<td><?php echo $da['reg_pass']; ?></td>
<td><?php $data = array(
'name' => 'reg_fname',
'id' => 'reg_id',
'value' => 'accept',
'checked' => TRUE,
'style' => 'margin:10px',
);
echo form_checkbox($data);?></td>
<td class="edit"><a title="Edit" href="edit-user.php"><img title="Edit" alt="Edit" src="images/edit_icon.png"></a></td>
<td class="del"><a title="Remove" href="#"><img title="Remove" alt="Remove" src="images/delete_item_btn.png"></a></td>
</tr>
<?php }?>
<?php }?>
</tbody>

You can send a AJAX Request to the CodeIgniter Controller. The Controller updates the database. As soon as a User wants to visit the site, you check if he has the right to do.
If a user should be immediately get the new right (for example if he is on the forbidden site), you need Websockets.
I hope this helps. Your Question only gives little information about your Problem. Do you want immediately set rights (-> AJAX)? Why not a Form? Maybe I'm wrong and you ask for a completely different causing.

Related

How to write php script to render html to another fille?

I have another php newbie question:
I writing a CRUD web app. I have a php file that will fetch data from database and saves the results as variables. Based on search results its rendering some html.
// after fetching data from database:
if (isset($_REQUEST['search'])) {
if (!$personnel && !$location && !$department) {
echo 'No results to show!';
} elseif ($personnel) {
?>
<table class="table">
<thead>
<tr>
<th>Last name</th>
<th>First name</th>
<th>Job Title</th>
<th>Email</th>
<th>Department</th>
<th>Location</th>
<th colspan="2">Action</th>
</tr>
</thead>
<?php
foreach ($output['data']['personnel'] as $row) :;
?>
<tr>
<td class="hidden"><?php echo $row['id'] ?></td>
<td><?php echo $row['lastName'] ?></td>
<td><?php echo $row['firstName'] ?></td>
<td><?php echo $row['jobTitle'] ?></td>
<td><?php echo $row['email'] ?></td>
<td><?php echo $row['department'] ?></td>
<td><?php echo $row['location'] ?></td>
<td><button class="btn btn-info editPersonnel">Edit</button>
Delete Personnel
</td>
</tr>
<?php endforeach; ?>
</table>
and so on.
Can someone tell me please how to change this script so it will render that table on my index page?
Workflow should be:
User typing something in the search box, the script is fetching the data, data is displayed on index page.
Thanks people!
Chi Chi

how can show 5 millons of data datatable in codeigniter

I am new in php. I want to show 5 Millions of record from my database in php in codeignter. I am using select star sql query to select table. It's working good but takes long time in loading data into datatable.
Any help would be appreciated.
Thanks in Advance.
<?php
include('layout/header.php');
include('layout/sidebar.php');
?>
<div data-widget-group="group1">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h2>Data Tables</h2>
<div class="panel-ctrls"></div>
</div>
<div class="panel-body no-padding table-responsive">
<form action="<?= base_url(); ?>signin/sendemailstudent" method="post">
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th style="padding-right:100px;">S.No</th>
<th>School</th>
<th>Date Of Admission</th>
<th>Register Serial</th>
<th>Student Name</th>
<th>Date Of Birth</th>
<th>Father Name </th>
<th>Phone </th>
<th>Email</th>
<th>Pincode</th>
<th>Class To Which Admitted</th>
<th>Class From Which Withdrawn</th>
<th>Date Of Withdrawl</th>
<th>Upload By</th>
<th>Notify<input type="checkbox" onclick="check();" id="select_all" name="select_all" /></th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
foreach ($data as $value) {
?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $value['school_name']; ?></td>
<td><?php echo $value['doa']; ?></td>
<td><?php echo $value['register_serial']; ?></td>
<td><a href='<?php echo base_url('signin/editstudent').'/'.$value['id']; ?>'><?php echo $value['name']; ?></a></td>
<td><?php echo $value['dob']; ?></td>
<td><?php echo $value['father_name']; ?></td>
<td><?php echo $value['phone']; ?></td>
<td><?php echo $value['email_address']; ?></td>
</tr>
<?php
$i++;
} ?>
<div class="clearfix pt-md">
</div>
</tbody>
</table>
</form>
</div>
<div class="panel-footer"></div>
</div>
</div>
</div>
</div>
<?php include('layout/footer.php'); ?>
As someone already mentioned:
paginate
filter
'using select star', dont use the star selector if you wont use all the fields.
codeignitter is using Active Record, something that uses DataMapper could be faster, not sure if you can change that though, most probably you can (havent use codeignitter). or using pure php pdo to deal with db.
have a look on how to use generators, they're much faster for processing big sets as they dont load everything in memory at once (that's what foreach would do)
not sure which version of php you're running, but if you're working on php <5.6 then you should definitely upgrade as new versions use much less memory/cpu for dealing with db.
install sql profiler to check if your queries are optimal.

How to select id from the datatables using checkbox

Heres my code: HTML with Server side to get data from the database. How do I get id from the datatables using checkbox option?
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<h4>
<th></th> <!-- For checkbox column-->
<th>ID Number</th>
<th>Lastname</th>
<th>Firstname</th>
<th>Middlename</th>
<th>Gender</th>
<th>Course</th>
<th>Department</th>
<th>Address</th>
<th>Contact</th>
<th>Birthdate</th>
<th>View</th>
<th>Events</th>
</h4>
</tr>
</thead>
<tbody>
<?php
include 'pgconnect.php';
$mydata = mysqli_query($conn,"SELECT * FROM student") or die(mysql_error());
while($record = mysqli_fetch_assoc($mydata))
{
$id=$record['id'];
?>
<tr>
<td><input type="checkbox"></td>
<td class="id"><?php echo $record['id'] ?></td>
<td class="lname"><?php echo $record['last_name'] ?></td>
<td class="fname"><?php echo $record['first_name'] ?></td>
<td class="mname"><?php echo $record['mid_name'] ?></td>
<td class="sex"><?php echo $record['gender'] ?></td>
<td class="course"><?php echo $record['course'] ?></td>
<td class="dept"><?php echo $record['department'] ?></td>
<td class="add"><?php echo $record['home_address'] ?></td>
<td class="contact"><?php echo $record['contact'] ?></td>
<td class="bdate"><?php echo $record['birthdate'] ?></td>
<td> View Records </td>
<td> <a title='Click here to update record.'href='#edit' data-toggle='modal'><i class="fa fa-pencil fa-fw"></i></a>
<a title='Click here to add record.' href='#'><i class="fa fa-plus fa-fw"></i></a>
<a title='Click here to delete record.' href='delete.php?del=<?php echo $record['id'] ?>'><i class="fa fa-trash-o fa-fw"></i></a></td>
</tr>
<?php
}
?>
</tbody>
</table>
Here's my script:
$(document).ready(function(){
$('#dataTables-example').dataTable();
});
I tried to get the ID but still it didn't works. Hope you can help me.
In your work, you get the ID in table. your should grab it from the checkbox if you use jquery, as in;
<script>
$(document).ready(function(){
document.getElementByID("ckmyid").innerHTML;
});
</script>
Note:add Selector ID in your checkbox, first, say, "ckmyid" so the code will be like this:
<input id="ckmyid" type="checkbox" value="<?php echo $record['id'] ?>">
Based on your structure, you can grab it directly from the link in your view records link if you want to place the ID there,as in;
<td> View Records </td>

ajaxForm 500 Internal Server Error

Hi im making an ajaxForm using comments.My problem is why the error is 500 Internal Server Error???, Well my codes and js library are in there, i dont quite understand why 500 internal server error.. Here's my code below.
<script>
$(document).ready(function(){
$("#tbl_comments").hide();
//$("#loading").hide();
$("#ptxt_green").hide();
$('#comment_form').ajaxForm({
target: '.result',
beforeSubmit: validate,
success: function(data) {
alert(data);
}
});
$("#loading")
.hide()
$(".result").show()
.ajaxStart(function(){
$(this).show();
$(".result").hide();
$("#loading").show();
})
.ajaxStop(function(){
$(this).hide();
$(".result").show();
})
;
});
function validate(){
var comment = $('textarea[name=txt_comment]').fieldValue();
if(!comment[0]){
$("#ptxt_green").fadeIn();
$("#ptxt_green").fadeOut(3000);
return false;
}
}
</script>
<?php $sf_response->setTitle(myTitleFactory::getPageTitle('seminar_detail', 'frontend',array('%seminar_title%'=>$seminar->getTitle())));?>
<?php myTools::loadBreadSlot(array(
myBreadcrumbFactory::get('seminar-list', 'frontend'),
myBreadcrumbFactory::get('seminar', 'frontend', array('slug' => $seminar->getSlug()), $seminar->getTitle())))
?>
<h1><?php echo $seminar->getTitle(); ?></h1>
<div class="table_seminar_wrap">
<table class="table_seminar" cellspacing="0" cellpadding="0" border="0" summary="info table">
<tr>
<th>Employee Id</th>
<td><?php echo $seminar->getId(); ?></td>
</tr>
<tr>
<th valign="top">情報公開日</th>
<td><?php echo $seminar->getPublishDate() .' '.$seminar->getPublishHour(); ?>時</td>
</tr>
<tr>
<th valign="top">セミナースキーム</th>
<td><?php echo $seminar->getStyle(); ?></td>
</tr>
<tr>
<th valign="top">日程</th>
<td><?php echo $seminar->getSeminarDate() .' '.$seminar->getStartTime() .' ~'.$seminar->getEndTime(); ?></td>
</tr>
<tr>
<th valign="top">前振りの文章</th>
<td><?php echo $seminar->getRawValue()->getSummary(); ?></td>
</tr>
<tr>
<th valign="top">タイトル</th>
<td><?php echo $seminar->getTitle(); ?></td>
</tr>
<tr>
<th valign="top">サブタイトル</th>
<td><?php echo $seminar->getSubTitle(); ?></td>
</tr>
<tr>
<th valign="top">開催地</th>
<td><?php echo $seminar->_getAddress(ESC_RAW); ?></td>
</tr>
<tr>
<th valign="top">会場</th>
<td>
<?php if($seminar->getLocationName()) : ?>
<?php echo $seminar->getLocationName(); ?><br>
<?php endif; ?>
<?php if($seminar->getRoomName()) : ?>
<?php echo $seminar->getRoomName(); ?>
<?php endif; ?>
</td>
</tr>
<?php if($seminar->getLocationName()) : ?>
<tr>
<th valign="top">会場URL</th>
<td><?php echo $seminar->getLocationUrl(); ?></td>
</tr>
<?php endif; ?>
<tr>
<th valign="top">内容</th>
<td><?php echo $seminar->getRawValue()->getDetail(); ?></td>
</tr>
<tr>
<th valign="top">キーチャート</th>
<td>
<?php if($seminar->getImagePath()): ?>
<a href="<?php echo $seminar->getImagePath(); ?>" target="_blank">
<img style="width:300px;" src="<?php echo $seminar->getImagePath(); ?>"/></a>
<?php endif; ?>
</td>
</tr>
<tr>
<th valign="top">対象</th>
<td>
<?php foreach($seminar->getTarget() as $target): ?>
<?php echo $target; ?>
<?php endforeach;?>
</td>
</tr>
<tr>
<th valign="top">定員・残席状況</th>
<td><?php echo $seminar->getCapacity(); ?>人</td>
</tr>
<tr>
<th valign="top">参加料</th>
<td><?php echo $seminar->getPrice(); ?></td>
</tr>
<tr>
<th valign="top">担当者</th>
<td><?php echo $seminar->getEmployee()->getName(); ?></td>
</tr>
<tr>
<th valign="top">講師</th>
<td>
<img class="instructorImage" alt="Instructor Image" src="<?php echo $seminar->getInstructor()->_getImagePath(); ?>" /><br>
<span><?php echo $seminar->getInstructor()->getName(); ?><span>
</td>
</tr>
<tr>
<th valign="top" style="width:170px">ご参加の皆様へのメッセージ</th>
<td><?php echo $seminar->getRawValue()->getMessage(); ?></td>
</tr>
<?php if($sf_user->isAuthenticated() && !$seminarXPerson): ?>
<tr>
<td style="text-align:center;" colspan="2">
<div class="blueBtnLink">
<span>応募する</span>
</div>
</td>
</tr>
<?php elseif(!$sf_user->isAuthenticated()): ?>
<tr>
<td style="text-align:center;" colspan="2">
<div class="blueBtnLink">
<span>応募する</span>
</div>
</td>
</tr>
<?php endif; ?>
</table>
<div id="ptxt_green">
<p>Please Write A Comments. . .</p>
</div>
<br />
<?php if($sf_user->isAuthenticated()): ?>
<form id="comment_form" action="<?php echo url_for('seminar/comment');?>" method="post">
<textarea id="txt_comment" name="txt_comment"></textarea>
<input type="submit" value="Write Comments" />
<br />
<br />
<div id="loading" style="text-align:center;">
<img alt="" src="/images/loading.gif" />
</div>
<div class="result">
<table id="tbl_comments">
<tr>
<td width="10%">Comments:</td>
<td>asasa</td>
</tr>
</table>
</div>
</form>
<?php endif; ?>
</div>
and my php file is this one
<?php
class commentAction extends sfAction{
public function execute($request){
echo "test"; exit();
//echo "qwqqwqqw"; exit();
//$post = $request->getParameter('seminar');
////print_r($post);exit();
//$comment = new SeminarComments();
//$comment->setComments($post['txt_comment']);
//$comment->save();
//$this->redirect('seminar');
}
}
?>
there.Why 500 internal server error? is this from the js? error?
neeeeeeeeeeed badly help
You have not provided enough info for anyone to give you a definitive answer, but here are some troubleshooting tips:
Check your server logs. To find where they are, see https://serverfault.com/questions/287079/cant-find-apache-error-logs and try to grep it out, here are a few to try (stolen directly from referenced ServerFault question)
grep ErrorLog /usr/local/etc/apache22/httpd.conf
grep ErrorLog /etc/apache2/apache2.conf
grep ErrorLog /etc/httpd/conf/httpd.conf
Once you find your server logs, find the log entry that corresponds to your 500 error. If you are having a hard time finding it, make another request with your client and then try to find the latest log entries.
Possible sources of error in your JavaScript include:
Calling the wrong URL
Calling the right URL but with the wrong parameters
Calling the right URL and parameters but with the wrong format (ie JSON vs XML)
Calling the right URL, parameters, and format but with wrong method (ie GET vs POST)
Calling the right URL/parameters/format/method but sending bogus data that the web server rejects (ie some servers are configured to automatically reject certain strings that look malicious)
By the way the server-side code you have posted does not tell the whole story. It is a simple class but rests on top of a complex framework, and you need to check the framework configuration to see if all is well. In particular, try calling the action directly (ie in your web browser, NOT through jQuery/JS). If it doesn't work, try calling a different action and see if it works. If you cannot get any action to work, it might be a framework config issue. I'm not familiar with symfony but if I were forced to become so I would start there.
If you can provide us the error log it would help greatly.
Try to call dev controller from your ajaxCall.
Normally you call index.php which is production controller and it doesn't provide any useful information about the error. Try to call front_dev.php instead which will return additional information about an error.
(the name of your dev controller is usually your app name suffixed with _dev.php so front_dev.php assumes your app name is front, which is default btw)

get the value of a checkbox then pass it to a link to edit a page

I have been working on this script that should get the value of an id field in a database through a checkbox that will be used by a link to edit a page. I know there are topics relating to this but non deals with using the value of the checkbox in a link. The checkbox is actually getting the value of the id from the database i know this because i used inspect element in firefox to view the value of the checkbox. The issue I'm having is using this value in a link to edit a page. Any help will be appreciated. My script is displayed below.
<td width="341" height="73"><h1><strong><span class="style2">EVENTS </span></strong></h1></td>
<td width="59" align="right"><div align="right"><strong>New</strong></div></td>
<td width="66" align="right"><div align="right"><strong><a href="edit_event.php?id=<?php
if (isset ($chek)) {
echo urlencode($chek);
}
?>"/>Edit</a></strong></div></td>
<td width="82" align="right"><div align="right"><strong>Archive</strong></div></td>
<td width="79" align="right"><div align="right"><strong>Unarchive</strong></div></td>
<td width="70" align="right"><div align="right"><strong>Delete</strong></div></td>
<td width="71" align="right"><div align="right"><strong>Exit</strong></div></td>
</tr>
</table>
<p> </p>
<table width="786" border="1">
<tr valign="top">
<th width="46">Event Title</th>
<th width="27"><input type="checkbox" name="checkbox1" value="checkbox" /></th>
<th width="37">Start Date</th>
<th width="36">End Date</th>
<th width="43">Start Time</th>
<th width="38">End Time</th>
<th width="43">Venue</th>
<th width="45">Event Type</th>
<th width="94">Event Description</th>
<th width="152">Event Program</th>
<th width="79">Reminder Date</th>
<th width="70">Reminder Time</th>
</tr>
<?php foreach($events as $event): ?>
<tr valign="top">
<td><?php echo $event->event_title; ?></td>
<td> <form id="form1" name="form1" method="post" action="">
<?php echo "<input type=\"checkbox\" name=\"chek[]\" value= $event->event_id id=\"chek\"/>"; ?>
</form>
</td>
<td><?php echo $event->start_date; ?></td>
<td><?php echo $event->end_date; ?></td>
<td><?php echo $event->start_time; ?></td>
<td><?php echo $event->end_time; ?></td>
<td><?php echo $event->venue; ?></td>
<td><?php echo $event->event_type; ?></td>
<td><?php echo $event->event_description; ?></td>
<td><?php echo $event->event_program; ?></td>
<td><?php echo $event->reminder_date; ?></td>
<td><?php echo $event->reminder_time; ?></td>
</tr>
<?php endforeach; ?>
<?php
$check = $_POST['chek'];
if(empty($check)){
$$check="";
}else{
$N = count($check);
for($i=0; $i < $N; $i++){
$chek =($check[$i]);
}
}
?>
I don't know if my question is understood, what i meant is that I want the value of my check box to display after (http://localhost/emgt/admin/edit_event.php?id=) id so i can edit that particular row.
You can check with the below link. It may be helpful for you.
As far I see you need to add class, and id to your checkbox and use a jquery/javascript function to call the value in your href.
Pass checkbox value to Edit (using href)
Hope it would be of some help to you.
I'm sorry, i found your code to be a little unclear. If you mean calling a url with the checkbox value as a parameter you can do so by adding an "id" property to the checkbox element, and then calling the page like:
var chk = document.getElementById("checkbox_id");
var url = "http://localhost/emgt/admin/edit_event.php?id=" + chk.value;
location.href = url;

Categories