I've been doing this for almost a month but I cannot figure it out on how to get the "details" of every row in my table. My table in my view is foreach. And post it in another page. By clicking the link named "Details..." on first page.
for example: ive searched in first page and this is the result:
column1 column1 column3 column4 column5 column6
name desc age num add Details...
name desc age num add Details...
When i click the first details... it would go to second page and post name, desc, age, num, add into textbox. same as the second details...
Any help would be greatly appreciated. Thanks.
here are my codes:
my model model.php - this is my code for search data in my database table
public function search_equip() {
if ($this->input->post('category') == "All")
{
$match = $this->input->post('search');
$array = array('column1' => $match);
$this->db->like($array);
$query = $this->db->get('equip');
return $query->result();
}
elseif ($this->input->post('category') == "Appliance")
{
$match = $this->input->post('search');
$array = array('column1' => $match, 'category' => "Appliance");
$this->db->like($array);
$query = $this->db->get('equip');
return $query->result();
}
elseif ($this->input->post('category') == "Furniture")
{
$match = $this->input->post('search');
$array = array('column1' => $match, 'category' => "Furniture");
$this->db->like($array);
$query = $this->db->get('equip');
return $query->result();
}
elseif ($this->input->post('category') == "Equipment")
{
$match = $this->input->post('search');
$array = array('column1' => $match, 'category' => "Equipment");
$this->db->like($array);
$query = $this->db->get('equip');
return $query->result();
}
}
my controller search.php - my code with set rules
function search_equipment()
{
//If searchbox is empty
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('search', 'Search', 'required|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('auth/index', 'refresh');
}
else
{
$data['query'] = $this->model->search_equip();
$this->load->view('auth/search_view_equipment', $data);
}
}
my view search_view_equipment.php - this is where i search data and show results with the link every row
<?php foreach($query as $item):?>
echo "<tr>";
echo "<td>".<?= $item->Column1 ?>."</td>";
echo "<td>".<?= $item->Column2 ?>."</td>";
echo "<td>".<?= $item->Column3 ?>."</td>";
echo "<td>".<?= $item->Column4 ?>."</td>";
echo "<td>".<?= $item->Column5 ?>."</td>";
echo "<td>".anchor("auth/view_equipment_details/".$item->Column6, 'Details...', array('class' => 'detail'))."</td>";
echo "</tr>";
<?php endforeach;?>
my second view view_equipment.php - this is where to post the data coming from first page (specific row)
Note: This td's are input, i dunno how to make a code here using input :)
<?php foreach($equipid as $item):?>
echo "<tr>";
echo "<td>".<?= $item->Column1 ?>."</td>";
echo "<td>".<?= $item->Column2 ?>."</td>";
echo "<td>".<?= $item->Column3 ?>."</td>";
echo "<td>".<?= $item->Column4 ?>."</td>";
echo "<td>".<?= $item->Column5 ?>."</td>";
echo "<td>".anchor("auth/view_equipment_details/".$item->Column6, 'Details...', array('class' => 'detail'))."</td>";
echo "</tr>";
<?php endforeach;?>
Is it possible to get that whole data of that row and show it in another page? Specifically, I'm confused on what am I going to do, because the table is in foreach. I cannot get the value of the specific link in first page, here's my code on getting the value of links in first page but im not succesful:
controller: auth.php
function view_equipment_details()
{
$data['equipid'] = $this->model->get_equipment_id();
$this->load->view('auth/view_equipment', $data);
}
model: addition in model.php
public function get_equipment_id() {
$match = $this->input->post(); //This line is where i want to put the specific links ( any links that i click in first page) VALUE or NAME or whatsoever that is EXACTLY THE SAME AS THE ID OF THAT ROW I WILL CLICK to search using (next line): all i need is the value equal to the id of a row in table in database.
$array = array('id' => $match);
$this->db->where($array);
$equipid = $this->db->get('equip');
return $equipid->result();
}
Thank you in advance for any help. Hoping for a feed back. :)
What a mess here budy ...
Your question is really confuse, but I think you are trying to make a link:
<?php echo anchor("auth/view_equipment_details/".$item->id, 'Details...', array('class' => 'detail')))?>
NOTE: its better to pass an id in the url (or a slug maybe), but not a field, Because you have to do a search in the requested controller using that id.
and then in AuthController the function called view_equipment_details:
public function view_equipment_details($id){
$this->data['equipment'] = $this->db->where('id', $id)->get('table_name')->row();
$this->load->view(auth/view_equipment', $this->data)
}
You are trying to get something from post, and thereÅ› nothing to do with post. The id should come as a parameter.
This way you can access your individual row details on another page.
For example you have page1 with table listing all the rows and a link as you shown for listing details in another page.
So attach ID to your details column within your url,so as per your code it goes like this
echo "<td>".anchor("auth/search_details/".$id_of_row, 'Details...', array('class' => 'detail'))."</td>";
Now in your controller function named 'search_details' will go like this :
function search_details ($row_id)
{
//code here to get/fetch row from database using $row_id
}
This way you can pass specific row details to another page.
Let me know if you any doubts further.
I figured it out. Thanks for your answers guys special.
My Model:
public function get_equipment_id($id) {
$array = array('id' => $id);
$this->db->where($array);
$equipid = $this->db->get('equip');
return $equipid->result();
}
My Controller:
function view_equipment_details($id)
{
$data['equipid'] = $this->model->get_equipment_id($id);
$this->load->view('auth/view_equipment', $data);
}
My View:
echo "<td>".anchor("auth/view_equipment_details/".$item->id, 'Details...', array('class' => 'detail'))."</td>";
Related
Can somebody tell me why my update did not work ?
Here are the data in my variable
$id = '1';
$table = 'tb_home_content';
$data = Array ( [title] => SLEEK DESIGN [content] => We have a sleek design which not only attractive but simple in design for our user to see. [classicon] => fa fa-clone );
Here are my model function
public function updateData($table, $data)
{
$id = $data['id'];
array_shift($data);
// echo $id.'<br>';
// echo $table.'<br>';
// print_r($data);
$this->db->where('id', $id);
$this->db->update($table, $data);
if($this->db->affected_rows() == '1')
{
echo "<script>";
echo "alert('Success');";
echo "</script>";
}
else
{
echo "<script>";
echo "alert('Failed');";
echo "</script>";
}
What is the error message you are getting? Are you sure the value at the position of id is the first element in the array?
I have a web application built using codeigniter. What I'm trying to do is show a summary of results on my view. In my controller I have the below code
function index() {
$data['summery'] = $this->Main_model->get_summery();
foreach ($data['summery'] as $d) {
$data['total_week'] = $this->Main_model->get_total_week($d['i_id']);
$data['total_month'] = $this->Main_model->get_total_month($d['i_id']);
}
}
The problem that im having is each summery record has total weekly count and a monthly count based on the i_id
in my view i loop through the summery and it display the summery but when i echo $total_week or echo $total_month its always returns NULL
$data['total_week'] = $this->Main_model->get_total_week($d['i_id']);
$data['total_month'] = $this->Main_model->get_total_month($d['i_id']);
When i do a var_dump on the above variables it shows the number, but when i try to echo it on the view it returns NULL
I hope I under stood correct Try something like this
function index() {
$this->load->model('main_model');
$data['summery'] = array();
$summery = $this->main_model->get_summery();
foreach ($summery as $d) {
$data['summery'][] = array(
'total_week' => $this->main_model->get_total_week($d['i_id']),
'total_month' => $this->main_model->get_total_month($d['i_id'])
);
}
$this->load->view('the_view', $data);
}
View
<?php foreach ($summery as $something) {?>
<?php echo $something['total_week'];?>
<?php echo $something['total_month'];?>
<?php }?>
I have this PHP code where I am loading a quiz into the view. When I select and submit an answer the view is changed and displays only the correct message or the wrong one.
What I am trying to achieve is when clicking the submit button for the answer, to keep the question and just display under if correct or not.
This is the code that I have:
function guess()
{
$guess = $this->input->get('name',false);
$personid = $this->input->get('id',false);
if ($guess === null) {
$newguess['data'] = $this->Starmodel->getQuestion();
$this->load->view('starview',$newguess);
}
else {
$res= $this->Starmodel->isCorrectAnswer($personid,$guess);
$person = $this->load->view('starview', array('iscorrect' => $res,
'name' => $guess));
}
}
My main view is starview.php. Can I use divs and target a specific load a view inside the specific div? How can I do this?
Thank you
Let say this your startview view...
//Your question goes here
//Answer part
<?php if($this->input->post()):
echo $answer_view_data
endif; ?>
In your function guess()
function guess()
{
$guess = $this->input->get('name',false);
$personid = $this->input->get('id',false);
if ($guess === null) {
$newguess['data'] = $this->Starmodel->getQuestion();
$this->load->view('starview',$newguess);
}
else {
$res= $this->Starmodel->isCorrectAnswer($personid,$guess);
$answer_data = 'Sample answer data';
$person = $this->load->view('starview', array('iscorrect' => $res,
'name' => $guess, 'answer_data' => $answer_data));
}
}
Request yo to help in pagination links .
In my database i have 3 records i want to display single record per page. When I select the next numeric of pagination link, data is not being fetched.Thing is that when I click on number 2 of pagination link, echo var_dump() shows Result is empty and I am not getting any values for echo $data->email.But for the first time when i search i am able to display single record, problem is only with next link of pagination So what might be the error? I'm not able to get an answer,and I'm not sure what happens, so I am posting my code below please go through it and and help me.
Request you to help me.
**HERE STARTS MY CONTROLLER**
public function users($limit=1,$offset = 0)
{
$this->load->helper('url');
$data = array();
$look = $this->input->post('look');
$age = $this->input->post('age');
$age_from = $this->input->post('age_from');
$age_to = $this->input->post('age_to');
$se_ct = $this->input->post('sect');
$subsect = $this->input->post('subsect');
$coun_try = $this->input->post('country');
$sta_te = $this->input->post('state');
$ci_ty = $this->input->post('city');
$qualification = $this->input->post('qualification');
$results = $this->searchresultss->login($look, $age, $age_to, $age_from, $se_ct, $subsect, $coun_try, $sta_te, $ci_ty, $qualification);
$this->load->helper('url');
$config = array();
$config['base_url'] = base_url().'searchresult/users';
$config['total_rows'] = count($results);
$config['per_page'] = $limit;
$this->load->library('pagination', $config);
$data['pagination_links'] = $this->pagination->create_links();
$data['results'] = array_slice($results, $offset, $limit);
$this->load->view('searchresult', $data);
$this->load->view('includes/khelp');
$this->load->view('includes/kfooter');
**HERE STARTS MY MODEL PAGE**
Class Searchresultss extends CI_Model
{
public function login($look, $age, $age_to, $age_from, $se_ct, $subsect, $coun_try, $sta_te, $ci_ty, $qualification)
{
return $this->db->query("SELECT *
FROM users
WHERE gender = '$look'
And status='1'")->result();
}
}
**HERE START MY VIEW PAGE**
echo var_dump($_POST);
if (empty($results)) {
echo 'Results set is empty';
} else
{
foreach ($results as $data) {
echo $data->email.'<br />';
}
}
echo $pagination_links;
The problem lies in the fact that the pagination links do not include the POST variables (as well as the fact that hyper links are requested via GET).
I recommend you do a var_dump() on $_GET and $_POST and the problem will become more obvious.
A possible solution would be to include the post variables as url parameters. So for example
$config['base_url'] = base_url().'searchresult/users/look_param/age_param/etcetc';
However you would need to add functionality to handle the above.
I am building a system in which the user can build thre own navigation menu from a selection of catergories, the way it works is that is they click on 'Blog' they they can get an accordion titled 'Blog' and on expanding this they see all the blog titles, however as the moment, my application creates multiple accordions if there are multiple blog entries, so at the moment i have two blog entries and when the user slects 'Blog' they get to accordions, where as they should get one with all the titles in
Controller:
public function category($content_id) {
//$this->output->enable_profiler(TRUE);
if (intval($this->uri->segments[4])){
$content_id = $this->uri->segments[4];
} else {
$content_id = $this->uri->segments[7];
}
$data['content'] = $this->site_model->get_content($content_id);
$this->load->view("call", $data);
}
Model:
public function get_content($content_id) {
$this->db->select('*');
$this->db->from ('content');
$this->db->join('categories', 'categories.category_id = content.categories_category_id', 'left');
$this->db->where ('categories_category_id', $content_id);
$query = $this->db->get();
return $query->result_array();
}
View:
<?php
if(isset($content)) {
// var_dump($content);
foreach($content as $row) {
echo "<h2 class='$row[category_name]'><a href='#'>$row[category_name]</a></h2>";
echo "<div class='$row[category_name]'><a href='index.php/home/get_content/$row[content_id]' class='contentlink'>$row[content_title]</a></div>";
}
}
?>
How can I alter my code so for category the user selects only one accordion gets built put all the categories realted content is placed in that accordion?
Hope this makes sense.
If I understand correctly you should move the creation of the header out of your loop:
<?php
if(isset($content)) {
echo "<h2 class='$category_name'><a href='#'>$category_name</a></h2>";
foreach($content as $row) {
echo "<div class='$row[category_name]'><a href='index.php/home/get_content/$row[content_id]' class='contentlink'>$row[content_title]</a></div>";
}
}
?>
If you don't know the category name you could try something like this:
<?php
$first = true;
if(isset($content)) {
echo "<h2 class='$category_name'><a href='#'>$category_name</a></h2>";
foreach($content as $row) {
if ($first) {
echo "<h2 class='$row[category_name]'><a href='#'>$row[category_name]</a></h2>";
$first = false;
}
echo "<div class='$row[category_name]'><a href='index.php/home/get_content/$row[content_id]' class='contentlink'>$row[content_title]</a></div>";
}
}
?>