My page is showing 4 updatable items. But when Update is clicked it is only updating the last item.
I have 3 different files I'll post. I've been working on this for days.
I got some advice on what to do, but the foreach on the core page seems like I'm missing somethings, but I cannot figure out what.
Display Page
<div class="cccm-dashboard-content-inner">
<div class="row">
</div>
<div class="ccm-dashboard-content-full">
<div class="row" style="padding-bottom:6px">
<div class="col-sm-6">Product Name -or- (SKU)</div>
<div class="col-sm-6"><a>Pricing</a></div>
</div>
<?php if (count($products) > 0) {
foreach ($products as $product) {
$pID = $product->getID();
$price = $product->getBasePrice() ?>
<form role="form" class="form-inline" method="post">
<div class="row" style="border-top:1px solid #333;padding:12px 0">
<div class="col-sm-6">
<input type="text" id="pName<?= $pID ?>" name="pName[]" value="<?= $product->getName() ?>" required="required" class="form-control ccm-input-text" style="width:100%;margin:1px"/>
<input type="text" id="pSKU<?= $pID ?>" name="pSKU[]" value="<?= $product->getSKU() ?>" placeholder="No SKU Set" maxlength="100" class="form-control ccm-input-text" style="width:100%;margin:1px"/>
<strong><?= t('Edit Page Directly') ?></strong>
</div>
<div class="col-sm-6">
<div class="input-group">
<input type="number" id="changeValue<?= $pID ?>" name="pPrice[]" value="<?= $price ?>" step="0.01" class="form-control ccm-input-number" style="width:100%;margin:1px"/>
</div>
</div>
<?= $token->output('community_store') ?>
<input type="hidden" name="pID[]" value="<?= $pID ?>"/>
</div>
<div class="ccm-dashboard-form-actions-wrapper">
<div class="ccm-dashboard-form-actions">
<button class="float-end pull-right btn btn-primary" type="submit[]"><?= t('Update All Products') ?></button>
</div>
</div>
</form>
<?php }
} ?>
</div>
</div>
This is my controller page:
class Pricing extends DashboardSitePageController {
public function view() {
if ($this->request->getMethod() == 'POST') {
$return = $this->save();
if ($return) {
return $return;
}
}
$this->loadFormAssets();
$this->set('product', $product);
$this->set('page', $page);
$productsList = new ProductList();
$ListItemsPerPage = 3;
$productsList->setItemsPerPage($ListItemsPerPage);
$productsList->setGroupMatchAny(true);
$this->set('productList', $productsList);
$factory = new PaginationFactory($this->app->make(Request::class));
$paginator = $factory->createPaginationObject($productsList);
$pagination = $paginator->renderDefaultView();
$this->set('products', $paginator->getCurrentPageResults());
$this->set('pagination', $pagination);
$this->set('paginator', $paginator);
$site = $this->getSite();
}
public function save() {
$data = $this->request->request->all();
if ($this->request->request->all() && $this->token->validate('community_store')) {
$product = ProductPricing::savePricing($data);
$event = new ProductEvent($originalProduct, $product);
Events::dispatch(ProductEvent::PRODUCT_UPDATE, $event);
if ($data['pID']) {
$this->flash('success', t('All Listed Products Updated'));
}
}
}
public function loadFormAssets() {
$this->requireAsset('css', 'select2');
$this->requireAsset('javascript', 'select2');
$this->set('al', $this->app->make('helper/concrete/asset_library'));
$this->requireAsset('css', 'communityStoreDashboard');
$this->requireAsset('javascript', 'communityStoreFunctions');
$pageType = PageType::getByHandle('store_product');
}
protected function getHeaderSearch($groupList, $gID) {
if (!isset($this->headerSearch)) {
$this->headerSearch = $this->app->make(ElementManager::class)->get('products/search', 'community_store', ['groupList'=>$groupList, 'gID'=>$gID]);
}
return $this->headerSearch;
}
}
This is the core page:
class ProductPricing extends Product {
/**
* #return \Concrete\Package\CommunityStorePricing\Src\CommunityStore\Product\ProductPricing
*/
public static function savePricing($data) {
$counter = 0;
foreach($data['pID'] as $aProductID) {
echo $data['pPrice'][$counter];
$product = self::getByID($data['pID'][$counter]);
$product->setName($data['pName'][$counter]);
$product->setSKU($data['pSKU'][$counter]);
$product->setPrice($data['pPrice'][$counter]);
$product->save($counter);
return $product;
$counter++;
}
}
}
return __NAMESPACE__;
Thank you Barman, this worked perfectly.
You're creating a separate form for each item. If you want to update all items at once, put the outside the foreach loop.
Take return $product out of the foreach loop. It's exiting the function after updating the first item.
Related
How do make my search work from a class... i can display my search results on the major page but i want it to display all results and if it is more than the paginated result, client can easily move to another page.
<?php
// if it's going to need the database, then it's
//probably smart to require it before we start.
#require_once(LIB_PATH.DS.'database.php');
class Product extends DatabaseObject {
protected static $table_name="products";
protected static $db_fields=array('id', 'product_id', 'image', 'title', 'slug', 'description', 'price');
public $id;
public $product_id;
public $image;
public $title;
public $slug;
public $description;
public $price;
public static function search(){
global $database;
$sql = "SELECT * FROM products WHERE image LIKE '{%$search%'";
$sql .= " OR title LIKE '{%$search%}'";
$sql .= " OR slug LIKE '%$search%'";
$sql .= " OR description LIKE '%$search%'";
$sql .= " OR price LIKE '%$search%'";
$total_count = count($sql);
$result_set = $database->query($total_count);
$row = $database->fetch_assoc($result_set);
return array_shift($row);
}
?>
Please check my code... i am a bit confused.
<?php if(empty($_POST['search'])){
$session->message("<div class='error-msg'>Search cannot be empty</div>");
redirect_to('photos.php');
}
?>
<?php include_layout_template('header2.php'); ?>
<div class="container">
<div class="row">
<?php
if(isset($_POST['submit'])){
// 1. the current page number ($current_page)
$page = !empty($_GET['page']) ? (int)$_GET['page'] : 1;
// 2. records per page ($per_page)
$per_page = 10;
// 3. total record count ($total_count)
//$total_count = Product::count_all();
$total_count = Product::search();
// Find all photos
// use pagination instead
$pagination = new Pagination($page, $per_page, $total_count);
// Instead of finding all records, just find the records
$search = $database->escape_value($_POST['search']);
// $sql = "SELECT * FROM products WHERE image LIKE '%$search%'";
// $sql .= " OR title LIKE '%$search%'";
// $sql .= " OR slug LIKE '%$search%'";
// $sql .= " OR description LIKE '%$search%'";
// $sql .= " OR price LIKE '%$search%'";
// $sql .= " LIMIT {$per_page} ";
// $sql .= "OFFSET {$pagination->offset()}";
$search = new Product();
$search->search = $search;
$photos = Product::find_by_sql($search);
//$total_count = count($photos);
//echo $numresults = '<p class="error-msg">There are '.$total_count.' results in your search</p><br/><br/>';
foreach ($photos as $photo): ?>
<div class="col-md-4 col-sm-6">
<div class="row">
<div id="pagination" style="clear: both;">
<nav aria-label="Page navigation example">
<ul class="pagination">
<?php
for($i=1; $i <= $pagination->total_pages(); $i++){
if($i == $page) {
// echo " <span class=\"selected\">{$i}</span> ";
// } else{
// echo " {$i} ";
}
}
if($pagination->total_pages() > 1) {
if($pagination->has_previous_page()) {
echo "<li class='page-item'><a class='page-link' href=\"search.php?page=";
echo $pagination->previous_page();
echo "\">« Previous</a></li> ";
}
if($pagination->has_next_page()){
echo "<li class='page-item'><a class='page-link' href=\"search.php?page=";
echo $pagination->next_page();
echo "\">Next »</a></li>";
}
}
?>
</ul>
</nav>
</div>
</div>
<div class="thumbnail">
<form method="post" action="cart.php?action=add&id=<?php echo $photo->id; ?>" role="form" class="form-vertical">
<a href="order_review.php?id=<?php echo $photo->id; ?>"><img src="<?php echo $photo->image_path();
?>" class="img-thumbnail" alt="responsive image"></a>
<div class="caption">
<h3 class="text-info text-center"><?php echo $photo->title; ?></h3>
<p class="text-muted text-center price card-header"><span class="currency">N</span><?php echo $photo->price; ?></p>
<p class="text-center"><em><?php echo $photo->description; ?></em></p>
<input type="hidden" name="id" class="form-control" value="<?php echo $photo->id; ?>" />
<input type="hidden" name="title" class="form-control" value="<?php echo $photo->title; ?>" />
<input type="hidden" name="slug" class="form-control" value="<?php echo $photo->slug; ?>" />
<input type="hidden" name="description" class="form-control" value="<?php echo $photo->description; ?>" />
<input type="hidden" name="price" class="form-control" value="<?php echo $photo->price; ?>"/>
<div class="col-sm-4 mx-auto d-block">
<select name="quantity" class="form-control" name="quantity">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
</div>
<div class="col-sm-4 col-sm-push-3 mx-auto d-block">
<input type="submit" name="add_to_cart" class="btn bg-success" value="Add to cart" />
</div><br/>
</form>
</div>
</div>
<?php endforeach; }
?>
</div>
</div>
PLease take note of the code i commented out... I am a bit confused.
I'm currently coding a blog to get experience with php.
In the edit.php I want to give the category of a post if a post has one.
This is the edit.php:
<div class="categories-heading">
<?php if (!empty($entry->c_Id)): ?>
<div class="category-heading">
<h3>Category: <?php echo e($categoryFromId); ?></h3>
</div>
<div class="category-heading">
<h3>change category</h3>
</div>
</div>
<form method="post">
<div class="categories-post-edit">
<?php foreach($categories as $cat): ?>
<div class="category-post-edit">
<input type="radio" name="category" value="<?php echo e($cat->id); ?>">
<label> <?php echo e($cat->category); ?></label>
</input>
</div>
<?php endforeach; ?>
</div>
</form>
<?php else: ?>
<div class="category-heading">
<h3>choose category</h3>
</div>
</div>
<form method="post">
<div class="categories-post-edit">
<?php foreach($categories as $cat): ?>
<div class="category-post-edit">
<input type="radio" name="category" value="<?php echo e($cat->id); ?>">
<label> <?php echo e($cat->category); ?></label>
</input>
</div>
<?php endforeach; ?>
This is the part of the function edit() in the PostsAdminController.php which is relevant for this:
if(!empty($_POST['title']) AND !empty($_POST['subheading']) AND
!empty($_POST['content'])
AND !empty($_POST['category'])) {
$entry->title = $_POST['title'];
$entry->subheading = $_POST['subheading'];
$entry->content = $_POST['content'];
$entry->c_Id = $_POST['category'];
$this->postsRepository->update($entry);
$savedSuccess = true;
}
$categoryFId = $this->categoryRepository->oneCategory($entry->c_Id);
$categoryFromId = $categoryFId['category'];
var_dump($categoryFromId);
$this->render("post/admin/edit", [
'entry' => $entry,
'savedSuccess' => $savedSuccess,
'categories' => $categories,
'categoryFromId' => $categoryFromId
]);
}
And this is the function oneCategory in the CategoryRepository.php that interacts with the database.
public function oneCategory($id)
{
$table = $this->getTableName();
$model = $this->getModelName();
$stmt = $this->pdo->prepare("SELECT `category` FROM `$table`
WHERE id = :id");
$stmt->setFetchMode(PDO::FETCH_CLASS, $model);
$oneCategory = $stmt->fetch(PDO::FETCH_CLASS);
return $oneCategory;
}
oneCategory() gives out an array no matter if I put SELECT * or SELECT category in the query, that's why I put $categoryFId['category'] into a variable after.
It works, but I think there must be a more easy or quicker way (like special functions or so), I just didn't manage to find what I search for
I'm trying to select one contract from the dropdown list, but it looks like the Ajax call is returning information for all contracts instead of just the id being sent. Bare in mind that I'm very new to ZF2.
// view.phtml
<script>
function loadContractId(id)
{
$.getJSON('<?php echo $this->basePath();?>/ajax/getId/'+id+'', function(data) {
$("#ctrid").text(data["arr"][0].ctr_id);
$("#ctrspec").text(data["arr"].ctr_spec);
$("#ctrnutype").text(data["arr"].ctr_nu_type);
$("#ctrlocationcity").text(data["arr"].ctr_location_c);
$("#ctrlocationstate").text(data["arr"].ctr_location_s);
$.each(data["arr"], function (index, item) {
console.log(item);
});
});
$("#contact_holder").css('visibility','visible');
}
</script>
<div id="loc_placement_panel" class="p0pup">
<form name="loc_placement_form" method="post" action="<?php echo $this->basePath(); ?>/booking/view/add">
<input type="hidden" name="ph_id" value="<?php echo $ar["ph_id"]; ?>">
<input type="hidden" name="pres_status" value="2">
<input type="hidden" name="ph_name" value="<?php echo $ar["ctct_name"]; ?>">
<!--<input type="hidden" name="addon" value="see below">-->
<strong>Placements</strong><br/><br/>
<label><strong>Contract:</strong></label>
<select name="contactlist" id="contactlist" onchange="loadContractId($('#contactlist').val())">
<?php
foreach ($ctrLT as $row=>$ar_contracts)
{
echo "<option value='".$ar_contracts['ctr_id']."'>";
echo $ar_contracts['ctr_no'];
echo "</option>";
}
?>
</select>
<div id="contact_holder" style="visibility: hidden">
<strong>Ctr id: </strong><span id="ctrid" ></span><br/>
<strong>Spec: </strong><span id="ctrspec" ></span><br/>
<strong>Nurse Type: </strong><span id="ctrnutype" ></span><br/>
<strong>City: </strong><span id="ctrlocationcity" ></span><br/>
<strong>State: </strong><span id="ctrlocationstate" ></span><br/>
</div>
<label><strong>User Name:</strong></label>
<input type="text" name="loc_location" id="loc_location" value="<?php echo $ar["ctct_name"]; ?>" />
<label><strong>$ltcontracts:</strong></label>
<textarea id="txtArea" rows="10" cols="100" name="loc_location" id="loc_location" value=""><?php '<pre>'; print_r($ltcontracts); '</pre>';?></textarea>
<br/><br/>
<!-- <input type="submit" value="Submit" id="loc_placement_submit_btn" name="loc_placement_submit_btn" /> -->
<input type="button" value="Cancel" id="loc_placement_cancel_btn" />
</form>
</div>
// AjaxController.php
// LT contracts
public function getId($id) {
$id = (int) $id;
return $this->getResortObject('retainedResort',$id);
}
// LT contracts
public function getIdAction() {
$result = new \stdClass();
$arr = $this->getContractsTable()->selectLtContracts($id);
$result->code = Response::STATUS_CODE_200;
$result->arr = $arr;
$json = Json::encode($result);
$response = $this->getResponse(); //new Response();
$response->setStatusCode($result->code);
$response->getHeaders()->addHeaders(array('Content-Type'=>'application/json'));
$response->setContent($json);
return $response;
}
// ContractTable.php
I tried also with selected id, ( $select->where('ctr_id = ?', $id); ) but it didn't work.
public function selectLtContracts($id = 0, array $ar = null) {
$this->table='allcontracts';
$select = new Select($this->table);
$select->where->like('ctr_no', '%LT');
$resultSet = $this->selectWith($select);
$ar = array();
if($resultSet)
{
$i=0;
foreach ($resultSet as $row) {
$ar[$i]['ctr_id']=$row->ctr_id;
$ar[$i]['ctr_no']=$row->ctr_no;
$ar[$i]['ctr_spec']=$row->ctr_spec;
$ar[$i]['ctr_nu_type']=$row->ctr_nu_type;
$ar[$i]['ctr_location_c']=$row->ctr_location_c;
$ar[$i]['ctr_location_s']=$row->ctr_location_s;
$ar[$i]['ctr_nurse']=$row->ctr_nurse;
$ar[$i]['ctr_type']=$row->ctr_type;
$ar[$i]['ctr_marketer']=$row->ctr_marketer;
$ar[$i]['ctr_recruiter']=$row->ctr_recruiter;
$i+=1;
}
}
return $ar;
}
This is what I'm getting from my console when I select a single contract from the dropdown list:
Any idea?
Basically I forgot to include in getIdAction() the single 'id' parameter from route:
$id = (int) $this->params()->fromRoute('id', 0);
and in the ContractsTable.php I needed to add equalTo() predicate:
...
if($id!='' && $id > 0)
$where->equalTo('ctr_id', $id);
$select->where($where);
...
How can I pass a variable from the model to the controller?
Here is my model:
public function edititem($id){
$query = $this->db->query('SELECT * FROM tblitem WHERE item_id = "$id"');
foreach ($query->result() as $row){
$name = $row->item_name;
$description = $row->item_description;
$price = $row->item_price;
}
And here is my controller
public function editItem(){
$this->load->helper('form');
$this->load->model('ItemModel');
$this->ItemModel->edititem($this->input->get('id'));
$name = $this->input->post('name');
$description = $this->input->post('description');
$price = $this->input->post('price');
$data['items'] = $this->ItemModel->itemlist();
$this->load->view('item/item_edit',$data);
}
In which when the user clicks "Edit Item", it will populate the form with the selected row.
<form action="<?php echo base_url().'item/edititem' ?> " method="post">
<div class="form-group">
<label for="name">Name</label>
<input type="name" class="form-control" id="name" name="name" placeholder="Name" value="<?php echo set_value('name'); ?>">
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea class="form-control" rows="3" name="description"><?php echo set_value('description'); ?></textarea>
</div>
<div class="form-group">
<label class="sr-only" for="price">Amount (in pesos)</label>
<div class="input-group">
<div class="input-group-addon">Php</div>
<input type="text" class="form-control" name="price" id="price" placeholder="Amount" value="<?php echo set_value('price'); ?>">
<div class="input-group-addon">.00</div>
</div>
</div>
<button type="submit" class="btn btn-primary">EDIT ITEM</button>
</form>
If it is from model to controller, You can make an array and store that 3 fields. (I assume there is only single row returned by your query since you are using id as where).
$result = array();
foreach ($query->result() as $row)
{
$result['name'] = $row->item_name;
$result['description'] = $row->item_description;
$result['price'] = $row->item_price;
}
return $result;
You can access it in the controller using:
$data['items']['name'];
$data['items']['description']
$data['items']['price']
Or in your view as
$items['name'];
$items['description'];
$items['price'];
Here your model looks like this
public function edititem($id){
$query = $this->db->query('SELECT * FROM tblitem WHERE item_id = "$id"');
if ($query->num_rows() > 0) {
$row = $query->row_array(); // row_array return single row and result_array return multiple row
return $row['dt'];
And your controller looks like this
public function editItem(){
$this->load->helper('form');
$this->load->model('ItemModel');
$item_details=$this->ItemModel->edititem($this->input->get('id'));
here you use foreach loop
foreach ($item_details as $key=>$value){
//do this in $data array
} //now you can use the specific data to your view.
$this->load->view('item/item_edit',$data);
}
Your Model:
This may useful if your want to return a specific 1 row without using result()
public function edititem($id){
$this->db->select('*');
$this->db->from('tblitem ');
$this->db->where('item_id ',$id);
return $query = $this->db->get()->custom_row_object(0, 'ItemModel');
}
Your Controller: Call the edititem($id) from ItemModel (your model)
public function editItem(){
$item_id=$this->uri->segment(3); //added this
$this->load->helper('form');
$this->load->model('ItemModel');
$item_details=$this->ItemModel->edititem($item_id); //added this
$data['item_name'] = $item_details->name;
$data['item_desc'] = $item_details->description;
$data['item_price'] = $item_details->price;
//now you can use the specific data to your view.
$this->load->view('item/item_edit',$data);
}
In your view, you can use the variable like:
$item_name;
$item_desc;
$item_price;
eg:
<input type="text" name="item_name" value="<?php echo $item_name;?>" />
OK, so I have looked everywhere for a solution to my problem but found none so far.My code looks like this.I have created a dynamic view page in which edit and add views are loaded dynamically.But the problem arises when i try to retain the value of select dropdown during editing.I would be grateful if someone could help me out.
View
<div class="panel-body">
<div class="row">
<div class="col-lg-6">
<?php if(#$patient_info){
echo '<h1 class="page-header">Edit Patient</h1>';
}else{
echo '<h1 class="page-header">Add Patient</h1>';
}
?>
<?php if($this->session->flashdata('error')){ ?>
<div class="alert alert-danger"><?php echo $this->session->flashdata('error'); ?></div>
<?php } ?>
<?php if($this->session->flashdata('erroredit')){ ?>
<div class="alert alert-danger"><?php echo $this->session->flashdata('erroredit'); ?></div>
<?php } ?>
<?php //echo validation_errors('<div class="alert alert-danger">','</div>'); ?>
<form role="form" method="post" action="<?php echo isset($patient_info) ? site_url('home/patient/edit') .'/' .$patient_info->patientID : site_url('home/patient/new'); ?>">
<div class="form-group">
<?php echo form_error('pname', '<div class="alert alert-danger">', '</div>'); ?>
<label for="pname">Patient Name</label>
<input class="form-control" placeholder="Enter Patient Name" name="pname" value="<?php echo isset($patient_info) ? $patient_info->patientName : ''; ?>">
</div>
<!-- Dropdown menu for selecting clinic -->
<div class="form-group">
<label for="select">Select Clinic Name</label>
<select class="form-control" name="selectClinic">
<option value="none">Select Clinic Below</option>
<?php foreach($allclinic as $key=>$clinic){ ?>
<!--<?php //foreach($clinicByPatient as $clin): ?>-->
<option value="<?php $clinic->clinicID; ?>"
<?php if(isset($patient_info)){
echo 'selected="selected"';
}
?>
>
<?php echo $clinic->clinicName; ?>
</option>
<?php //endforeach; ?>
<?php } ?>
</select>
</div>
<!-- Select Clinic ends-->
<div class="form-group">
<label for="select">Select Dentist</label>
<select class="form-control" name="selectDentist">
<option value="">Select Dentist</option>
<?php foreach($dentistdet as $key=>$dentist){ ?>
<option value="<?php echo $did = $dentist->dentistID;?>"><?php echo $dentist->dentistName; ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary btn-lg btn-block" name="submit" value="<?php echo isset($patient_info) ? 'Update Patient' : 'Add Patient'; ?>" >
</div>
</form>
<div class="form-group">
<input type="submit" class="btn btn-danger btn-lg btn-block" value="Cancel">
</div>
Edit controller
public function edit(){
$id = $this->uri->segment(4);
$this->load->library('form_validation');
$this->load->model('clinic_model');
$this->load->model('dentist_model');
$data['patient_info'] = $this->patient_model->getPatientById($id);
$data['clinicByPatient'] = $this->patient_model->getPatientByClinic();
$data['allclinic'] = $this->clinic_model->getAllClinics();
// $data['clinicdet'] = $this->patient_model->getPatientByClinic();
if($_POST){
$this->form_validation->set_rules('pname', 'Patient Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('paddress', 'Patient Address', 'trim|required|xss_clean');
$this->form_validation->set_rules('pcontact', 'Patient Contact', 'trim|required|xss_clean');
if($this->form_validation->run()== FALSE){
$data['subview'] = 'patient/patient_new';
$this->load->view('includes/layout', $data);
}else{
$patientname = $this->input->post('pname');
$patientaddress = $this->input->post('paddress');
$patientcontact = $this->input->post('pcontact');
$select = $this->input->post('selectClinic');
$option = $this->input->post('selectDentist');
$edited = $this->patient_model->editpatient($id, $patientname, $patientaddress, $patientcontact, $select, $option);
if($edited){
$this->session->set_flashdata('successedit', 'Successfully updated the record');
redirect('home/patient');
}
}
}else{
$data['subview'] = 'patient/patient_new';
$this->load->view('includes/layout',$data);
}
}
Model looks like this
<?php if( ! defined('BASEPATH')) exit('No direct script access allowed');
class Patient_model extends CI_Model{
public function countPatients(){
$countPatient = $this->db->count_all('patient');
return $countPatient;
}
public function getallpatients(){
$query = $this->db->get('patient');
if($query->num_rows()>0){
return $query->result();
}
else{
return FALSE;
}
}//getallpatients function ends
public function getPatientByClinic(){
$this->db->select('*');
$this->db->from('patient');
$this->db->join('clinic', 'patient.clinicID = clinic.clinicID', 'left');
$this->db->join('dentist', 'patient.dentistID = dentist.dentistID', 'left');
$query = $this->db->get();
if($query->num_rows>0){
return $query->result();
}
}
public function addPatientByClinic($patientname, $patientadd, $patientcontact, $select, $option){
$data = array(
'patientName' => $patientname,
'patientAddress' => $patientadd,
'patientContact' => $patientcontact,
'clinicID' => $select,
'dentistID' => $option
);
return $this->db->insert('patient',$data);
}// method ends
public function deletePatient($id){
$verifyID = array('patientID' => $id);
// $affRows = $this->db->affected_rows();
// $obj = new Patient_model;
if($verifyID){
$this->db->where($verifyID);
$this->db->delete('patient');
if($this->db->affected_rows()){
return TRUE;
}
}
}
public function editpatient($id, $patientname, $patientaddress, $patientcontact, $select, $option){
$data = array(
'patientName' => $patientname,
'patientAddress' => $patientaddress,
'patientContact' => $patientcontact,
'clinicID' => $select,
'dentistID' => $option
);
$query = $this->db->where('patientID', $id)
->update('patient', $data);
if($query){
return true;
}
}//method ends
public function getPatientById($id){
$query = $this->db->where('patientID', $id)
->get('patient');
return $query->row();
}
}//class ends
?>
In the code for your select box, you aren't actually echoing $clinic->clinicID. Thus, when the form is submitted, the value will be empty.
You also need to be careful with how you are choosing which select element will be selected by default - you aren't comparing with anything that will change within the loop. Should you be checking against $clinic->clinicID?