This is a strange one, i have ammended my mysql queries to show only results "WHERE domain_available='Y' AND domain_category!='N/A' AND domain_crawler_id='0'" when i manually go in to PHPMyAdmin and do an sql query test it brings back the proper results (57) but when i run the script the rows count: echo $total_results; brings back all 1300+ results, even though i manually test in the phpmyadmin query table, it brings back the results perfectly.
<?php
include('includes/sessions.php');
include('includes/db_connection.php');
include('includes/functions.php');
include('includes/header.php');
include('includes/navbar-logged.php');
?>
<?php
$crawlId = isset($_GET['urlId']) ? $_GET['urlId'] : '';
?>
<?php
if (!isset($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page'];
}
$userInfo = get_logged_in_users_details($member);
$canEdit = false;
if ($userInfo['user_class'] === 'Site Administrator') {
$canEdit = true;
}
$sort = isset($_GET['sort']) ? $_GET['sort'] : 'domain_id';
$max_results = 500;
$from = ($page * $max_results) - $max_results;
if (isset($crawlId)) {
$rows = DB::getInstance()->select("
SELECT *
FROM `domains`
WHERE `domain_available`='Y' AND `domain_crawler_id`='{$crawlId}'
ORDER BY `{$sort}` DESC
LIMIT :from, :max_results",
[
'from' => [
'type' => PDO::PARAM_INT,
'value' => $from
],
'max_results' => [
'type' => PDO::PARAM_INT,
'value' => $max_results
]
]);
} else {
$rows = DB::getInstance()->select("
SELECT *
FROM `domains`
WHERE `domain_available`='Y' AND `domain_category`!='N/A' AND `domain_crawler_id`='0'
ORDER BY `{$sort}` DESC
LIMIT :from, :max_results",
[
'from' => [
'type' => PDO::PARAM_INT,
'value' => $from
],
'max_results' => [
'type' => PDO::PARAM_INT,
'value' => $max_results
]
]);
}
if (isset($crawlId)) {
$total_results = DB::getInstance()->selectValue("SELECT count(*) FROM `domains` WHERE`domain_crawler_id`='{$crawlId}'");
} else {
$total_results = DB::getInstance()->selectValue("SELECT count(*) FROM `domains` WHERE `domain_available`='Y' AND `domain_category`!='N/A' AND `domain_crawler_id`='0'");
}
echo $total_results;
if (count($rows) < 1) {
stderr('Sorry, <b>no</b> domains to show you yet!');
}
$backLinksData = getBackLinksByDomains($rows);
$isPremiumUser = (int)$user['paid_fees'] === 1;
?>
<div class="panel panel-primary">
<div class="panel-heading">Search for expired domains quickly.</div>
<div class="panel-body">
<form action="results.php" method="get" class="form-horizontal container-fluid" role="form">
<div class="row form-group">
<div class="col-sm-6 text-right">
<label for="" class="control-label">Domain Contains:</label>
</div>
<div class="col-sm-6">
<input type="text" name="keywords" class="form-control" size="40" />
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label for="" class="control-label">Anchor Contains:</label>
</div>
<div class="col-sm-6">
<input type="text" name="anchor" class="form-control" size="40" />
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label class="control-label">DA:</label>
</div>
<div class="col-sm-6">
<input type="number" min="0" max="100" name="da" value="0" class="form-control" />
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label class="control-label">PA:</label>
</div>
<div class="col-sm-6">
<input type="number" min="0" max="100" name="pa" value="0" class="form-control" />
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label class="control-label">TF:</label>
</div>
<div class="col-sm-6">
<input type="number" min="0" max="100" name="tf" value="0" class="form-control" />
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label class="control-label">CF:</label>
</div>
<div class="col-sm-6">
<input type="number" min="0" max="100" name="cf" value="0" class="form-control" />
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label class="control-label">Domains Born After:</label>
</div>
<div class="col-sm-6">
<input type="number" min="1990" max="2016" name="age" value="1999" class="form-control" />
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label class="control-label" style="display: inline-block;"> </label>
</div>
<div class="col-sm-6 text-right">
<button type="submit" name="submit" class="btn btn-default">Search</button>
</div>
</div>
</form>
</div>
<div class="panel-footer">Search for domains using <b>your</b> criteria.</div>
</div>
<div class="panel panel-primary">
<div class="panel-heading">Browse Domains - <b>*<font color="orange">spam</font>*</b> = Potential spam domain! <b>*<font color="red">HP</font>*</b> = A homepage link points to this domain!</div>
<div class="panel-body">
<table class="table table-striped table-condensed table-hover table-responsive">
<thead>
<tr>
<th>Alexa</th>
<th>Domain / Category</th>
<th>DA</th>
<th>PA</th>
<th>TF</th>
<th>CF</th>
<th>Indexed</th>
<th>Age</th>
<th>BL</th>
<th>RD</th>
<th>Found</th>
<?php if ($canEdit): ?>
<th>Actions</th>
<?php endif; ?>
</tr>
</thead>
<tbody>
<?php foreach ($rows as $row) { ?>
<?php
//$bgcolor = ($bgcolor == '#eeeeee'? '#ffffff': '#eeeeee');
$domID = $row['domain_id'];
$domNM = $row['domain_name'];
$domDT = $row['domain_date'];
$domAL = $row['domain_alexa_rank'];
$domDA = $row['domain_moz_da'];
$domPA = $row['domain_moz_pa'];
$domTF = $row['domain_tf'];
$domCF = $row['domain_cf'];
$domRD = $row['domain_ref_domains'];
$domDC = $row['domain_age'];
$domIN = $row['domain_indexed'];
$domHP = $row['domain_homepage'];
$domCT = $row['domain_category'];
$time_1 = date('Y-m-d H:i:s', strtotime($domDT . ' +1 hour'));
$time_2 = date('Y-m-d H:i:s', time());
$string = $domNM;
$array = array("sunglasses","payday","casino","viagra","cashloans","loans","sex","porn","xxx");
$spam = 0;
foreach ($array as $token) {
if (stristr($string, $token) !== FALSE) {
$spam = 1;
}
}
?>
<tr>
<td><?php echo htmlspecialchars($domAL); ?></td>
<td>
<?php
$domainUrl = $isPremiumUser ? $domNM : getObscuredUrl($domNM);
$domainCat = ($domCT == "N/A") ? "<font color=\"red\"><b>Uncategorized</b></font>" : "<font color=\"green\"><b>{$domCT}</b></font>";
?>
<b><?php echo htmlspecialchars($domainUrl); ?></b> <b>in</b> <?php echo $domainCat; ?>
<?php if ($time_2 <= $time_1) { ?>
<b>(<font color="red">NEW</font>)</b>
<?php } ?>
<?php if ($spam) { ?>
<b>*<font color="orange">spam</font>*</b>
<?php } ?>
<?php if ($domHP) { ?>
<b>*<font color="red">HP</font>*</b>
<?php } ?>
</td>
<td>
<?php echo $domDA; ?>
</td>
<td>
<?php echo $domPA; ?>
</td>
<td>
<?php echo $domTF; ?>
</td>
<td>
<?php echo $domCF; ?>
</td>
<td>
G=<?php if ($domIN == 0) { echo "<font color=\"red\"><b>No</b></font>"; } else { echo "<font color=\"green\"><b>Yes</b></font>"; } ?>
</td>
<td>
<?php if ($domDC == "????") { echo "<b><font color=\"red\">????</font></b>"; } else { echo $domDC; } ?>
</td>
<td>
<?= isset($backLinksData[$domNM]) ? $backLinksData[$domNM] : 0; ?>
</td>
<td>
<?php if (empty($domRD)) { echo "-"; } else { echo $domRD; } ?>
</td>
<td>
<b><?php echo date("m.d.y", strtotime($domDT)); ?></b>
</td>
<?php if ($canEdit): ?>
<td>(e)-(d)</td>
<?php endif; ?>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="panel-footer text-center">
<?php pagination($page, $total_results, $max_results) ?>
</div>
</div>
<?php
include('includes/footer.php');
I cannot see why the query works in phpmyadmin, but fails when i run the script, is there something i have overlooked, and help would be appreciated.
$crawlId is always set here, because you set it at the very top. You set it to '' though, which will still count as set.
So you might wanna use if(!empty($crawlId)) {...} instead of isset()
Related
hey I'm Newbie and want to edit php page and adding some extra code so my problem is
I added new column to my table and I want to send data from new input text to my table to new column
I add the input text and now I wand to insert that data in new column
even I didn't find the insert query to editing it
my code is below
<?php include_once 'asset/admin-ajax.php'; ?>
<?php echo message_box('success'); ?>
<?php echo message_box('error'); ?>
<div class="row">
<div class="col-sm-12">
<div class="wrap-fpanel">
<div class="panel panel-default" data-collapsed="0">
<div class="panel-heading">
<div class="panel-title">
<strong><?php echo $this->language->form_heading()[13] ?></strong>
</div>
</div>
<div class="panel-body">
<form id="form" action="<?php echo base_url() ?>admin/employee/save_employee_award/<?php
if (!empty($award_info->employee_award_id)) {
echo $award_info->employee_award_id;
}
?>" method="post" enctype="multipart/form-data" class="form-horizontal">
<div class="panel_controls">
<div class="form-group" id="border-none">
<label for="field-1" class="col-sm-3 control-label"><?php echo $this->language->from_body()[14][0] ?> <span class="required">*</span></label>
<div class="col-sm-5">
<select name="designations_id" class="form-control" onchange="get_employee_by_designations_id(this.value)">
<option value="">اختر تعيين.....</option>
<?php if (!empty($all_department_info)): foreach ($all_department_info as $dept_name => $v_department_info) : ?>
<?php if (!empty($v_department_info)): ?>
<optgroup label="<?php echo $dept_name; ?>">
<?php foreach ($v_department_info as $designation) : ?>
<option value="<?php echo $designation->designations_id; ?>"
<?php
if (!empty($award_info->designations_id)) {
echo $designation->designations_id == $award_info->designations_id ? 'selected' : '';
}
?>><?php echo $designation->designations ?></option>
<?php endforeach; ?>
</optgroup>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
</div>
<div class="form-group" id="border-none">
<label for="field-1" class="col-sm-3 control-label"><?php echo $this->language->from_body()[14][1] ?> <span class="required">*</span></label>
<div class="col-sm-5">
<select name="employee_id" id="employee" class="form-control" >
<option value="">اختر موظف...</option>
<?php if (!empty($employee_info)): ?>
<?php foreach ($employee_info as $v_employee) : ?>
<option value="<?php echo $v_employee->employee_id; ?>"
<?php
if (!empty($award_info->employee_id)) {
echo $v_employee->employee_id == $award_info->employee_id ? 'selected' : '';
}
?>><?php echo $v_employee->first_name . ' ' . $v_employee->last_name ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
</div>
<div class="form-group">
<label for="field-1" class="col-sm-3 control-label"><?php echo $this->language->from_body()[14][2] ?> <span class="required">*</span></label>
<div class="col-sm-5">
<input type="text" name="award_name" class="form-control" value="<?php
if (!empty($award_info->award_name)) {
echo $award_info->award_name;
}
?>" />
</div>
</div>
<div class="form-group">
<label for="field-1" class="col-sm-3 control-label"> new column <span class="required">*</span></label>
<div class="col-sm-5">
<input type="text" name="new_column" class="form-control" value="<?php
if (!empty($award_info->new_column)) {
echo $award_info->new_column;
}
?>" />
</div>
</div>
<div class="form-group">
<label for="field-1" class="col-sm-3 control-label"><?php echo $this->language->from_body()[14][3] ?></label>
<div class="col-sm-5">
<input type="text" name="gift_item" class="form-control" value="<?php
if (!empty($award_info->gift_item)) {
echo $award_info->gift_item;
}
?>" />
</div>
</div>
<div class="form-group">
<label for="field-1" class="col-sm-3 control-label"><?php echo $this->language->from_body()[14][4] ?></label>
<div class="col-sm-5">
<input type="text" name="award_amount" class="form-control" value="<?php
if (!empty($award_info->award_amount)) {
echo $award_info->award_amount;
}
?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"><?php echo $this->language->from_body()[14][5] ?> <span class="required">*</span></label>
<div class="col-sm-5">
<div class="input-group">
<input type="text" name="award_date" placeholder="ادخل الشهر" class="form-control monthyear" value="<?php
if (!empty($award_info->award_date)) {
echo $award_info->award_date;
}
?>" data-format="dd-mm-yyyy">
<div class="input-group-addon">
<i class="entypo-calendar"></i>
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-5">
<button type="submit" id="sbtn" name="sbtn" value="1" class="btn btn-primary"><?php echo $this->language->from_body()[1][12] ?></button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12" data-offset="0">
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">
<span>
<strong><?php echo $this->language->from_body()[14][6] ?></strong>
</span>
</div>
</div>
<!-- Table -->
<table class="table table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th class="col-sm-1">رقم الموظف</th>
<th>اسم الموظف</th>
<th>اسم المكافئة</th>
<th>بند المكافئة</th>
<th>مبلغ الكافئة</th>
<th>الشهر</th>
<th> : اجراء</th>
</tr>
</thead>
<tbody>
<?php if (!empty($all_employee_award_info)):foreach ($all_employee_award_info as $v_award_info): ?>
<tr>
<td><?php echo $v_award_info->employment_id ?></td>
<td><?php echo $v_award_info->first_name . ' ' . $v_award_info->last_name; ?></td>
<td><?php echo $v_award_info->award_name;?></td>
<td><?php echo $v_award_info->gift_item; ?></td>
<td><?php echo $v_award_info->award_amount;?></td>
<td><?php echo date('F y', strtotime($v_award_info->award_date)) ?></td>
<td>
<?php echo btn_edit('admin/employee/employee_award/' . $v_award_info->employee_award_id . '/' . $v_award_info->designations_id); ?>
<?php echo btn_delete('admin/employee/delete_employee_award/' . $v_award_info->employee_award_id); ?>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
anyone for help please
To check the full path of the file copy paste the code at the top of the file and then you can easily go to the directory where the file is located.
<? echo base_url().'admin/employee/save_employee_award/'; exit; ?>
I am getting the following error:
http://localhost/sites/admin_panel/student_center_system/controller/admin/editmaster.php?item_id=Notice: Undefined variable: row in C:\xampp\htdocs\sites\admin_panel\student_center_system\controller\admin\viewitems.php on line 49
when i click edit button on viewitem.php nothing shows up in the form it is empty this viewitems.php The database connection is working perfect but the problem is the edit form .Ihave been stack for two days with this problem about edit form not working.could someone help me please i will appreciate thank you.
<?php
include "navigation.php";
include "header.php";
include "footer.php";
?>
<?php
include("../dbConfig.php");
$query = "SELECT item_id,item_name,description,item_category,pic FROM lost_items_table";
$returnD = mysql_query($query);
$returnD1 = mysql_query($query);
$result = mysql_fetch_assoc($returnD);
?>
<!-- Page Content -->
<div id="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">View Items</h1>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">View Items</div>
<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
<tr>
<th>Item Id</th>
<th>Item Name</th>
<th>Description</th>
<th>Item category</th>
<th>Picture</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<?php
while($result1 = mysql_fetch_assoc($returnD1)){
?>
<tr>
<td>
<?php echo $result1['item_id']; ?>
</td>
<td><?php echo ucfirst($result1['item_name']); ?></td>
<td><?php echo ucfirst($result1['description']); ?></td>
<td><?php echo ucfirst($result1['item_category']); ?></td>
<td><?php echo ucfirst($result1['pic']); ?></td>
<td>
Edit
</td>
<td>
Delete
</td>
</tr>
<?php
}
?>
</table>
<!-- /.table-responsive -->
</div>
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
</div>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
</div>
</div>
this is editmaster.php file.this is the form for editing data and nothing is showing up in the form its empty.what could be wrong with my code .
<?php session_start();
include("../dbConfig.php");
include "navigation.php";
include "header.php";
include "footer.php";
{
}
$item_id = '';
$item_name = '';
$description = '';
$item_category = '';
$pic = '';
if (isset($_POST['updateitem']))
{
if (is_numeric($_POST['item_id']))
{
$item_id = $_POST['item_id'];
$item_name = mysql_real_escape_string(htmlspecialchars($_POST['item_name']));
$description = mysql_real_escape_string(htmlspecialchars($_POST['description']));
$item_category = mysql_real_escape_string(htmlspecialchars($_POST['item_category']));
$pic = mysql_real_escape_string(htmlspecialchars($_POST['pic']));
if ($item_name == '' || $description == '' || $item_category == '' || $pic == '')
{
$error = 'ERROR: Please fill in all required fields!';
valid($item_id, $item_name, $description, $item_category, $pic, $error);
}
else
{
mysql_query("UPDATE lost_items_table SET item_name = '$item_name', description = '$description', item_category = '$item_category', pic = '$pic' WHERE item_id = '$item_id'")
or die(mysql_error());
header("Location: viewitems.php");
}
}
else
{
echo 'Error!';
}
}
else
{
if (isset($_GET['item_id']) && is_numeric($_GET['item_id']) && $_GET['item_id'] > 0)
{
$item_id = $_GET['item_id'];
$result = mysql_query("SELECT * FROM lost_items_table WHERE item_id=$item_id")
or die(mysql_error());
$row = mysql_fetch_array($result);
if($row)
{
$item_name = $row['item_name'];
$description = $row['description'];
$item_category = $row['item_category'];
$pic = $row['pic'];
valid($item_id, $item_name, $description, $item_category, $pic,'');
}
else
{
echo "No results!";
}
}
else
{
echo 'Error!';
}
}
?>
<!-- Page Content -->
<div id="page-wrapper">
<div class="container-fluid">
<!-- /.row -->
<div class="row">
<!--div class="col-md-8 col-md-offset-4"-->
<div class="col-lg-6">
<div class="Register-panel panel panel-default">
<!--div class="panel panel-default"-->
<div class="panel-heading">
Edit Item
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-6">
<div class="panel-body">
<form role="form" action="adminPage.php">
<input type="text" name="item_id" value=<?php echo $item_id; ?> readonly><br>
<input type="text" name="item_name" required autofocus placeholder="Item-Name" value=<?php echo $item_name; ?>><br>
<input type="text" name="description" required autofocus placeholder="Description" value=<?php echo $description; ?>><br>
<input type="text" name="item_category" required autofocus placeholder="Item_category" valu
e=<?php echo $item_category; ?>><br>
<input type="text" name="pic" required autofocus placeholder="pic" value=<?php echo $pic; ?>><br>
<input type="submit" name="updateitemBtn" value="Update">
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Hello im just a newbie in codeigniter and i just want to ask on how to fix this problem...
i just want to make a simple quiz system and i want to shuffle all the questions from my database and display it.. the problem is when i compare the questions choices it gives me a value of unshuffle how can i solve this?
this is my controller to display my questions
public function quiz()
{
if(isset($_SESSION['username'])) {
$this->load->model('quizmodel');
$this->data['questions'] = $this->quizmodel->getQuestions();
$this->load->view('client/quiz', $this->data);
}else{
$this->load->view('home');
}
}
this is the getQuestions function from my quizmodel
public function getQuestions()
{
$this->db->select("cropscience_id, question, choice1, choice2, choice3, answer");
$this->db->from("cropscience");
$query = $this->db->get();
return $query->result();
$num_data_returned = $query->num_rows;
if ($num_data_returned < 1) {
echo "There is no data in the database";
exit();
}
}
this is my quiz view
<div class="panel-body">
<form method="post" action="<?php echo base_url();?>index.php/client_controller/resultdisplay">
<?php shuffle($questions); ?>
<?php foreach($questions as $row) { ?>
<?php $ans_array = array($row->choice1, $row->choice2, $row->choice3, $row->answer);
shuffle($ans_array); ?>
<div class="alert alert-success">
<p><?=$row->question?></p>
<br>
<div class="radio radio-success radio-inline">
<input type="radio" name="<?php echo $row->cropscience_id ?>" value="<?=$ans_array[0]?>" required>
<label for="inlineRadio1"> <?=$ans_array[0]?> </label>
</div>
<div class="radio radio-success radio-inline">
<input type="radio" name="<?php echo $row->cropscience_id ?>" value="<?=$ans_array[1]?>">
<label for="inlineRadio1"> <?=$ans_array[1]?> </label>
</div>
<div class="radio radio-success radio-inline">
<input type="radio" name="<?php echo $row->cropscience_id ?>" value="<?=$ans_array[2]?>">
<label for="inlineRadio1"> <?=$ans_array[2]?> </label>
</div>
<div class="radio radio-success radio-inline">
<input type="radio" name="<?php echo $row->cropscience_id ?>" value="<?=$ans_array[3]?>">
<label for="inlineRadio1"> <?=$ans_array[3]?> </label>
</div>
</div>
<?php } ?>
<div align="center" >
<div class="btn btn-primary btn-rounded">
<i class="fa fa-check"></i><input class="btn btn-primary btn-rounded" type="submit" value="Submit!">
</div>
</div>
</form>
</div>
this is my resultdisplay function from my controller
public function resultdisplay()
{
if(isset($_SESSION['username'])) {
$this->load->model('quizmodel');
$qID = $this->quizmodel->getQuizID();
$this->data['checks'] = $this->input->post($qID);
$this->load->model('quizmodel');
$this->data['results'] = $this->quizmodel->resultsScore();
$this->load->view('client/result_display', $this->data);
}else{
$this->load->view('home');
}
}
this is my result_display view
div class="wrapper wrapper-content">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h1 style="color: white;">Results</h1>
</div>
<div class="panel-body">
<?php $score = 0; ?>
<?php $array1= array(); ?>
<?php $array2= array(); ?>
<?php $array3= array(); ?>
<?php $array4= array(); ?>
<?php $array5= array(); ?>
<?php $array6= array(); ?>
<?php $array7= array(); ?>
<?php $array8= array(); ?>
<?php $count = 0; ?>
<?php foreach($checks as $checkans) { ?>
<?php echo $checkans; ?>
<?php $array1[$count] = $checkans;
$count++; ?>
<?php }?>
<br><br>
<?php foreach($results as $res) { ?>
<?php $array2[] = $res->answer;
$array3[] = $res->cropscience_id;
$array4[] = $res->question;
$array5[] = $res->choice1;
$array6[] = $res->choice2;
$array7[] = $res->choice3; ?>
<?php } ?>
<?php for ($x=0; $x <= $array3[$x]; $x++) { ?>
<?php echo $array4[$x]; ?>
<?php if ($array2[$x] != $array1[$x]) { ?>
<div class="alert alert-danger">
<p><i class="fa fa-times"></i></p>
<p><span style="background-color: #FF9C9E"><?=$array1[$x]?></span></p>
<p><span style="background-color: #ADFFB4"><?=$array2[$x]?></span></p>
</div>
<?php } else { ?>
<div class="alert alert-success">
<p><i class="fa fa-check"></i></p>
<p><span style="background-color: #ADFFB4"><?=$array1[$x]?></span></p>
</div>
<?php $score = $score + 1 ?>
<?php } ?>
<?php } ?>
<div align="center">
<input type="hidden" name="score" value="<?=$score?>">
<input type="button" class="btn btn-primary" data-toggle="modal" data-target="#scoremodal" value="View Your Score">
<!-- Score Modal Body -->
<div class="modal inmodal fade" id="scoremodal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-body" align="center">
<h2>Your Score is: </h2>
<h1><?=$score?>/100</h1>
</div>
<div class="modal-footer">
<?php echo form_open('client_controller/save_score'); ?>
<form method="get">
<div align="center">
<input type="hidden" name="score" value="<?=$score?>">
<input type="submit" class="btn btn-primary" value="Ok">
</div>
</form>
<?php echo form_close(); ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
this is my getQuizID() function model
public function getQuizID()
{
$this->db->select("cropscience_id");
$this->db->from("cropscience");
$query = $this->db->get();
}
this is my resultsScore() function model
public function resultsScore()
{
$this->db->select("cropscience_id, question, choice1, choice2, choice3, answer");
$this->db->from("cropscience");
$query = $this->db->get();
return $query->result();
$num_data_returned = $query->num_rows;
}
please help thank you
make a query like this:
$this->db->order_by('id', 'RANDOM');
or
$this->db->order_by('rand()');
$query = $this->db->get('cropscience');
return $query->result_array();
I am not able to update multiple columns of the same row with the row matching the userid in codeigniter.
My controller Code is :
exits.php
function update_act_on_resignation(){
global $SITE,$USER;
$data = array();
$data['row'] = new stdClass();
$data['row'] = $this->admin_init_elements->set_post_vals($this->input->post());
$data['offices']=$this->mod_common->get_all_offices();
$clients = currentuserclients();
$data['roles'] = $this->mod_common->get_cat_array('designation','status',"1' AND id > '0",'designation');
get_city_state_country_array($data,array('cityid'=>$data['row']->cityid));
$data['error_message'] = '';
$data['row']->id = $this->uri->segment(3);
$data['id'] = $this->uri->segment(3);
$data['action'] = 'add';
$data['heading'] = 'Add';
$data['msg_class'] = 'sukses';
$data['path']=$path;
$post_action = $this->input->post('action');
if($post_action=='add' || $post_action =='update' ){
$post_array = $this->input->post();
$action = ($post_action == 'add')?'inserted':'updated';
//echo '<pre>';print_r($SITE);die;
echo $post_array['exit_type'] = 'Employee Initiated';
echo $post_array[$id] = $USER->id;
echo $post_array['custom-105965'];
echo $post_array['manager_comments'];
echo $post_array['accept'];
echo $post_array['agreed_last_date'];
$data['success_message'] = $this->exit_common->update_get_resignation_to_act($post_array,$action);
if($data['success_message'] == 'Record '.$action.' successfully'){
$data['row'] = new stdClass();
$data['row']->id = $this->uri->segment(3);
$data['row']->status = 1;
}
}
$this->data['maincontent'] = $this->load->view('maincontents/view_resignation_action', $data,true);
echo "Resignation withdrawn successfully!";
$this->load->view('layout', $this->data);
}
I am echoing the results got from a form to check if i am receiving the sent form elements and i have received everything properly. i.e i am recieving 67 for $post_array[$id] Yes for $post_array['custom-105965'] asd for $post_array['manager_comments'] Accept for $post_array['accept'] and 01-01-1970 as $post_array['agreed_last_date'] after the echo.
My Model code is:
exit_common.php
function update_get_resignation_to_act($post_array,$action){
$this->load->database();
$this->db->where('userids', $post_array['id']);
$dbdata['discussion'] = $post_array['custom-105965'];
$dbdata['manager_comments'] = $post_array['manager_comments'];
$dbdata['last_status'] = $post_array['accept'];
$dbdata['agreed_date'] = $post_array['agreed_last_date'];
$this->db->update('pr_resignation_requests', $dbdata);
return;
}
I think something is wrong with the model update function. But not able to figure out what is wrong as a similar function is working for updating a single column in db. Am i missing something? Its a mysql db.
My View Code is:
view_resignation_action.php
<style>
label{font-weight:bold;}
.hbox .col {
display: table-cell;
float: none;
height: 100%;
vertical-align: top;
width:100%;
}
</style>
<div class="new">
<section class="content-header">
<h1>
Resignation Action
</h1>
<ol class="breadcrumb" >
<li><i class="fa fa-home"></i> Home</li>
<li>People Connect</li>
<li>Exit Tracker</li>
<li class="active">Exit Details</li>
</ol>
</section>
<input type="hidden" id="page_name" value="requests">
<div class="container-fluid">
<div class="row">
<!-- Thought Day-->
<div class="panel wrapper clearfix m-b-none">
<!-- Horizontal Form -->
<div class="box-header with-border">
</div><!-- /.box-header -->
<!-- form start -->
<?php if($error_message!=''){?>
<div class="row-fluid return-message success-message <?php echo $msg_class; ?>"><?php echo $error_message;?></div>
<?php } else { ?>
<?php echo form_open('exits/update_act_on_resignation/',array('name'=>'addostcstevent','id'=>'addostcstevent','method'=>'post','autocomplete'=>'on','class'=>'form-horizontal'))?>
<?php echo form_hidden(array('id'=>$USER->id,'action'=>$action));?>
<?php foreach($rows as $row){ ?>
<div class="panel-body">
<div class="control-group form-group">
<div class="col-md-6">
<div class="controls">
<div class="col-md-5">
<label class="control-label" style="text-align:left">Name of the employee </label>
<div class="controls"><?php echo $row->firstname; ?>
</div>
</div>
<div class="col-md-5">
</div>
</div>
</div>
<div class="col-md-6 pull-right">
<label class="control-label" style="text-align:left">Date of request </label><div class="controls">
<?php echo $row->resignations_date; ?>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="control-group form-group">
<div class="col-md-6 ">
<label class="control-label" style="text-align:left">Requested Last Working Date</label>
<div class="controls">
<div class="col-md-10">
<?php echo $row->requested_date; ?>
</div>
</div>
</div>
<div class="col-md-6 pull-right">
<label class="control-label">Reason</label>
<div class="controls">
<div class="col-md-9">
<?php echo $row->exit_type; ?>
</div>
</div>
</div>
<div class="col-md-6 pull-right">
<label class="control-label">Comments from Employee</label>
<div class="controls">
<div class="col-md-9">
<?php echo $row->comments; ?>
</div>
</div>
</div>
<br><br><br><br><br><br><br>
<fieldset id="f1" class="col-md-6 pull-left"> <!-- start fieldset -->
<div class="label">
</label>
</div>
<div class="input">
</div>
</div>
</td>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" style="text-align:left">
<label class="control-label" style="text-align:left">Have you had a discussion with Employee?</label>
<table>
<td valign="top">
<input id="custom-105965_0" class="custom-105965" name="custom-105965" value="Yes" type="radio">
<label for="custom-105965_0">Yes
<br>
</label>
</td>
<td valign="top">
<input id="custom-105965_1" class="custom-105965" name="custom-105965" value="No" type="radio">
<label for="custom-105965_1">No
</label>
</td>
</table>
<td valign="top">
<div class="fieldset" id="bsd-field-custom-105967-group">
<div class="col-md-6 pull-left">
<label class="control-label">Please enter your comments</label>
<div class="controls">
<div class="col-md-12">
<textarea required class="form-control" name="manager_comments"></textarea>
<!--<input placeholder="Please enter your comments" class="" id="dateofrequest" type="text" name="todays_date" value=""/> <br><br>-->
</div>
</div>
<label class="control-label">Action</label>
<div class="controls">
<div class="col-md-9">
<?php $dd_list = array(
'Accept' => 'Accepted',
'Reject' => 'Rejected',
);
echo form_dropdown('accept', $dd_list, 'Accept');
?>
</div>
</div>
<label class="control-label">Agreed Last Working day</label>
<div class="controls">
<div class="col-md-9">
<input placeholder="Agreed Last Working day" class=" m-wrap col-md-8 form-control " id="startdt" type="text" name="agreed_last_date" value="<?php if($row->requested_date!='') echo date("d-m-Y",$row->requested_date); ?>" required/>
</div>
</div>
<br><br>
<div class="col-md-9">
</div>
</div>
</div>
<!-- If its a no -->
<div class="fieldset" id="bsd-field-custom-105867-group">
<div class="col-md-6 pull-left">
<div class="alert alert-success alert-dismissable">
<label type="button"></label>
Please have a discussion with the employee.
</div>
</div>
</div>
</td>
</table>
</td>
</tr>
</fieldset><!-- End Fiedset -->
</div>
</div>
<?php }?>
<div class="clearfix"></div>
<div class=" box-footer">
<button type="submit" class="btn btn-info pull-right" style="margin:0px 10px">submit</button>
</div>
</form>
<?php } ?>
<div class="clearfix"></div>
</div>
</div>
</div>
</section>
</div>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/plugins/bootstrap-fileupload/bootstrap-fileupload.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/plugins/select2/select2.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/plugins/bootstrap-timepicker/js/bootstrap-timepicker.js"></script>
<script>
$(".fieldset").hide();
$(document).ready(function () {
$("[id^=bsd-field-custom-1059]").hide();
$(".custom-105965").change(function () {
$("[id^=bsd-field-custom-1059]").toggle(this.value == 'Yes');
});
});
$(document).ready(function () {
$("[id^=bsd-field-custom-1059]").hide();
$(".custom-105965").change(function () {
$("[id^=bsd-field-custom-1058]").toggle(this.value == 'No');
$('.alert').show()
});
});
$(document).ready(function(){
$("#startdt").datepicker({
dateFormat: 'dd-mm-yy',
changeMonth: true,
changeYear: true,
showButtonPanel: true,
yearRange: "-90:+0",
endDate: new Date(),
autoclose: true
}).on('changeDate', function (selected) {
var minDate = new Date(selected.date.valueOf());
$('#enddt').datepicker('setStartDate', minDate);
});
$("#enddt").datepicker({
dateFormat: 'dd-mm-yy',
changeMonth: true,
changeYear: true,
showButtonPanel: true,
yearRange: "-90:+0",
endDate: new Date()
});
$(".date-picker").datepicker();
$('.timepicker-default').timepicker();
$('#report_date').datepicker( {
format: "mm-yyyy",
viewMode: "months",
minViewMode: "months"
});
$(".select2").select2({
placeholder: "Select an option",
allowClear: true
});
$("#asset_type").change(function(){
if($(this).val() == '-1') {
$("#new_type").show();
}
else
{
$("#new_type").hide();
}
});
$("#manufacturer").change(function(){
if($(this).val() == '-1') {
$("#new_manufacturer").show();
}
else
{
$("#new_manufacturer").hide();
}
});
$("#supplier").change(function(){
if($(this).val() == '-1') {
$("#new_supplier").show();
}
else
{
$("#new_supplier").hide();
}
});
});
</script>
Mysql Table is :
Try Below Snippet
function update_get_resignation_to_act($post_array,$action)
{
$this->load->database();
$this->db->where('userids', $post_array['id']);
$dbdata = array(
"discussion" => $post_array['custom-105965'],
"manager_comments" => $post_array['manager_comments'],
"last_status" => $post_array['accept'],
"agreed_date" => $post_array['agreed_last_date']
);
$this->db->update('pr_resignation_requests', $dbdata);
/**
* if required add this code here to check
*
* echo $this->db->last_query();
*/
return;
}
I have built a page with CodeIgniter, that has a search function and a datatable.
Whenever I click the search button, the datatable will change accordingly to the parameter submitted. But it not working as I expected.
This is My Model
public function ocsmodel($biostype=null, $manufacture=null)
{
// Loading second db and running query.
if ($biostype==null and $manufacture == Null) {
$this->ocs = $this->load->database('ocsweb', TRUE);
return $this->ocs->select('ocslist.*')
->from('ocslist')
->limit(100)
->get();
}
else {
if ($manufacture == "") {
}
else {
$this->ocs = $this->load->database('ocsweb', TRUE);
return $this->ocs->select('ocslist.*')
->from('ocslist')
->where('bios_type',$biostype)
->where('smanufature',$manufacture)
->limit(100)
->get();
}
}
}
This is my controller
public function ocslist()
{
$manufactur ="";
$biostype ="";
if (isset($_POST['bios_type'])){
$biostype = $this->input->post('bios_type');
if (isset($_POST['manufacture'])){
$manufactur = $this->input->post('manufacture');
}
$data['ocs'] = $this->assetmodel->ocsmodel()->result_array();
}
else {
$data['ocs'] = $this->assetmodel->ocsmodel($biostype,$manufactur)->result_array();
}
$data['ocstype'] = $this->assetmodel->getocstype()->result_array();
$data['ocsmanu'] = $this->assetmodel->getocsmanu()->result_array();
$data['content'] = 'master/ocs_list';
$this->load->view('template', $data, FALSE);
}
And This is My View
<div class="right_col" role="main">
<div class="">
<div class="page-title">
<!--<div class="title_left">
<h3>
Master Department
<small>
List
</small>
</h3>
</div> -->
</div>
<div class="clearfix"></div>
<div class = "row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>OCS INVENTORY LIST</h2>
<ul class="nav navbar-right panel_toolbox">
<li><i class="fa fa-chevron-up"></i>
</li>
<li class="dropdown">
<i class="fa fa-wrench"></i>
</li>
<li><i class="fa fa-close"></i>
</li>
</ul>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
<div class="x_content">
<!-- search parameters -->
<form class="form-default" method="POST" action="<? echo base_url('asset/ocslist'); ?>">
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="bios_type">Type <span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select class="select2_single form-control" tabindex="-1" name="bios_type">
<?php foreach ($ocstype as $key => $value) { ?>
<option value="<? echo $value['bios_type']?>"><? echo $value['bios_type']?></option>}
<? } ?>
</select>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="manufacture">Manufacture </label>
<div class="col-md-3">
<select class="select2_single form-control" tabindex="1" name="manufacture">
<?php foreach ($ocsmanu as $key => $value) { ?>
<option value="<? echo $value['smanufacturer']?>"><? echo $value['smanufacturer']?></option>}
<? } ?>
</select>
</div>
</div>
<div>
<button type="button" class="btn btn-info" name="submit">Search</button>
Master Asset
</div>
</div>
</form>
<table id="datatable-fixed-header" class="table responsive-utilities table-bordered">
<thead>
<tr>
<th>Type</th>
<th>Device ID</th>
<th>Manufacture</th>
<th>Model</th>
<th>Nama</th>
<<th>User ID</th>
<th>Mac_Address</th>
<th>Serial Number</th>
<th>Asset</th>
</tr>
</thead>
<tbody>
<?php foreach ($ocs as $key => $value) { ?>
<tr>
<td><?php echo $value['bios_type'];?> </td>
<td><?php echo $value['DEVICEID'];?> </td>
<td><?php echo $value['SMANUFACTURER'];?> </td>
<td><?php echo $value['smodel'];?> </td>
<td><?php echo $value['name'];?> </td>
<td><?php echo $value['userid'];?> </td>
<td><?php echo $value['macaddr'];?> </td>
<td><?php echo $value['SSN'];?> </td>
<td>Add Asset</td>
</tr>
<? } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
what about changing your controller into something like
public function ocslist()
{
$data['ocs'] = $this->assetmodel->ocsmodel($this->input->post('bios_type'), $this->input->post('manufacture'))->result_array();
$data['ocstype'] = $this->assetmodel->getocstype()->result_array();
$data['ocsmanu'] = $this->assetmodel->getocsmanu()->result_array();
$data['content'] = 'master/ocs_list';
$this->load->view('template', $data, FALSE);
}
because CI sets all POST Data to null if they doesn't exist
For more information look here
Update (20.07.2016)
according to your view try to change the button type into something like this
<button type="submit" class="btn btn-info" name="submit">Search</button>