php Dynamic HTML cell generates unexpectedly - php

I am currently working on interface part a framework to generate HTML tags. Problem i am facing is while generating tags for nested tables and cells.
for this purpose, I have one html class which define common expectation of tags. Another class is htmlTable which is inherited from hrml class and customised for table, TR, TD. While i want to add nested tables on a particular cell, the result is unexpected. It generates hundreds of TDs and TRs.
Following code is customised to post here as putting all code will make long and too confusing.
And one more thing, I am only concentrated to solve logical error to get exact parent, child and nested elements of HTML tag.
I have tried as much as i could but couldnot get this fixed. This might be easy for some of you. So please advice me your solution. I have got to go to work so will reply only once i get back.
Thnak you
<?php
// scHTML.php
class HTML
{
protected $tag;
protected $id;
protected $values;
protected $childList;
protected $body;
public function __construct($tag,$id)
{
$this->tag=$tag;
$value= array('id'=>$id);
$this->setValues($value);
}
// to add nested tag
public function addChildTag(HTML $child)
{
$this->childList[]=$child;
}
// to add key and value on opening tag
public function setValues($values)
{
if(count($values)>0)
{
foreach($values as $key=>$value)
{
$this->values[$key]=$values;
}
}
}
// value inside tag
public function setBody($body)
{
$this->body=$body;
}
// generate HTML code
public function getHTML()
{
$return= '<'.$this->tag;
if(count($this->values)>0)
{
foreach($this->values as $key=>$value)
{
$return.=' '.$key.'= "'.$value.'" ';
}
}
$return.= '>
';
if(count($this->childList)>0)
{
$return.=
$this->body
;
foreach($this->childList as $child)
{
$return.=
$child->getHTML();
}
}
$return.=' </'.$this->tag.'>';
return $return;
}
public function __toString()
{
return $this->getHTML();
}
}
?>
and here is the inherited class for table
<?php
//scHTMLTable.php
include_once("scHTML.php");
class HTMLTable extends HTML
{
protected $cells; // logical grid of cells for current table
protected $row;
protected $column;
public function __construct($row,$column,$id)
{
$this->row=$row;
$this->column=$column;
$this->initiateTable();
$values['border']='1px';
$this->setValues($values);
parent::__construct("table",$id);
}
// initaite table cells according to row and column provided
private function initiateTable()
{
$td=new HTML("td",NULL);
$td->setBody(' ');
for($i=1;$i<=$this->row;$i++)
{
for($j=1;$j<=$this->column;$j++)
{
$this->addCell($i,$j,$td);
}
}
}
// set child element as body on a cell
public function addChildOnCell($row,$column,HTML $child)
{
$td=$this->cells[$row][$column];
$td->addChildTag($child);
$this->addCell($row,$column,$child);
}
// set cell
public function addCell($row,$column,HTML $cell)
{
$this->cells[$row][$column]=$cell;
}
// set TR as child and call parent method to generate html code.
public function getHTML()
{
for($i=1;$i<=$this->row;$i++)
{
$tr=new HTML("tr",NULL);
for($j=1;$j<=$this->column;$j++)
{
$td=$this->cells[$i][$j];
$tr->addChildTag($td);
}
$this->addChildTag($tr);
}
return parent::getHTML();
}
public function __toString()
{
return $this->getHTML();
}
}
?>
And here is the implementation.
<?php
include_once("scHTML.php");
include_once("scHTMLTable.php");
$html= new HTML("html",NULL);
$body=new HTML("body",NULL);
// three table to be tested
$a= new HTMLTable(3,3,"grandparent");
$b=new HTMLTable(3,3,"parent");
$c=new HTMLTable(1,1,"child");
$b->addChildOnCell(2,2,$c);
$a->addChildOnCell(2,2,$b);
$body->addChildTag($a);
$html->addChildTag($body);
echo $html;
?>
Output i am looking as source code is somewhere near this
<html>
<body>
<table border="1">
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><table border="1">
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><table border="1">
<tr>
<td> </td>
</tr>
</table></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>

I agree with MrMesees in that I think your table class is doing too much and that each node type is only responsible for generating it's own DOM representation. Any to-string / to-html recursion should only move downward through the DOM, though (no calls to parents for rendering assistance). Here is a quick demo using some of your custom API method names:
class HTML
{
private $tagName;
protected $attributes = [];
protected $children = [];
private $text = '';
public function __construct($tagName, $text='') {
$this->tagName = strtolower($tagName);
$this->text = $text;
}
public function addChildTag(HTML $n) {
$this->children[] = $n;
return $this;
}
public function getHTML($depth=0) {
$padding = str_repeat("\t", $depth);
$result = "$padding<$this->tagName";
foreach($this->attributes as $k => $v) {
$result .= " $k=\"".htmlspecialchars($v)."\"";
}
if (count($this->children) == 0 && strlen($this->text) == 0) {
$result .= " />\n";
}
else {
$result .= ">";
$result .= $this->text;
if (count($this->children) > 0) $result .= "\n";
foreach($this->children as $c) {
$result .= $c->getHTML($depth+1);
}
$result .= "$padding</$this->tagName>\n";
}
return $result;
}
public function tagName() { return $this->tagName; }
public function findChild($tagName, $index=0) {
$nodes = array_filter($this->children, function($e) use ($tagName) { return $e->tagName() == $tagName; });
return count($nodes) ? $nodes[$index] : null;
}
public function __toString() { return $this->getHTML(); }
}
class HTMLTable extends HTML {
public function __construct($rows, $cols, $id) {
parent::__construct("table");
$this->attributes['id'] = $id;
$this->attributes['border'] = '1px';
for($r=0; $r<$rows; $r++) {
$row = new HTML("tr");
for($c=0; $c<$cols; $c++) {
$cell = new HTML("td");
$row->addChildTag($cell);
}
$this->addChildTag($row);
}
}
public function addChildOnCell($row, $col, HTML $child) {
return $this->findChild("tr", $row-1)->findChild("td", $col-1)->addChildTag($child);
}
}
$html= new HTML("html");
$body=new HTML("body");
// three table to be tested
$a= new HTMLTable(3,3,"grandparent");
$b=new HTMLTable(3,3,"parent");
$c=new HTMLTable(1,1,"child");
$b->addChildOnCell(2,2,$c);
$a->addChildOnCell(2,2,$b);
$body->addChildTag($a);
$html->addChildTag($body);
echo $html;
Which results in output:
<html>
<body>
<table id="grandparent" border="1px">
<tr>
<td />
<td />
<td />
</tr>
<tr>
<td />
<td>
<table id="parent" border="1px">
<tr>
<td />
<td />
<td />
</tr>
<tr>
<td />
<td>
<table id="child" border="1px">
<tr>
<td />
</tr>
</table>
</td>
<td />
</tr>
<tr>
<td />
<td />
<td />
</tr>
</table>
</td>
<td />
</tr>
<tr>
<td />
<td />
<td />
</tr>
</table>
</body>
</html>

It's 2015, you should not be manually including files; there are clear coding-standards, so you should have namespaces and register an auto-loader in your main App.
Also as long as you are going to string build in this way, using the __toString() method on objects representing the tables, you should just have other classes for the nested parts, each with their own __toString method; so you can have HTMLElement class (you've got), with table (you have but it's not ideal), table-row, table-cell.
Extending this, you should if you take this route extend all HTMLElements, and have a rawString HTMLElement extended class for when you feel like just getting things done parrot fashion.
table row __toString method would just iterate over contained cells and return their __toString methods
table would iterate over rows and call their __toString method
table cell (the most / least difficult part), would take instances implementing HTMLElement, and iterate over them calling their __toString method
It's a lot cleaner method of working than the current, and then as each outputs it's own DOM, you should be free of the nasty bug you have now.
If the table gets too large, you are going to wish you had just coded a series of views that work with one-level of XYdata, or simplified in another way; but the data structures to this sort of nested view, unless you are working with JSON or XML anyway (in the case of XML, just use XSL); are not going to be nice to retrieve from say SQL Server, MySQL, search upon, or really to do that many useful things with...

Related

Use return data from one function in another and pass it to Smarty template

What I'm trying to do is to have one datatable probably as a template and passing different datas on different pages.
Example functions.php
function force() {
global $DBconn;
$q = "SELECT * FROM table";
$res = $DBconn->query($q);
return $this->result;
}
function force_1() {
global $DBconn;
$q = "SELECT * FROM table_1";
$res = $DBconn->query($q);
return $this->result;
}
function table() {
echo '
<table class="sortable">
<thead>
<tr>
<th>
Title
</th>
</tr>
</thead>
<tbody>';
foreach ($this->result as $key) {
echo ' <tr>
<td>
$key->name
</td>
</tr>';
}
echo '</tbody>
</table>';
}
return true;
}
Then in the page.php
$table = table();
$smarty->assign("table", $table);
and page.tpl
<div> {$table} </div>
Currently nothing showed on page, not even an error or something. So:
Is this the way that should be done? With using the returned result in either function and then pass it to the smarty template?
I don't know how to use the smarty template (I never used it), but the $table variable holds what the function table() returns (in your case, the boolean value true). It should return a string, like this:
function force() {
// corrected the function force return value, assuming that you are using PDO connection
global $DBconn;
$q = "SELECT * FROM table";
$res = $DBconn->query($q);
return $res->fetchAll(PDO::FETCH_ASSOC);
}
function table() {
$arr = force();
return
'
<table class="sortable">
<thead>
<tr>
<th>
Title
</th>
</tr>
</thead>
<tbody>';
foreach ($arr as $row) {
echo " <tr>
<td>
$row['name']
</td>
</tr>";
}
echo '</tbody>
</table>';
}
You should be also careful with quotes when using variables inside a string.
EDIT:
If you are using mysqli class
function force() {
global $DBconn;
$q = "SELECT * FROM table";
return $DBconn->query($q);
}
function table() {
$result = force();
return
'
<table class="sortable">
<thead>
<tr>
<th>
Title
</th>
</tr>
</thead>
<tbody>';
//while ($row = $result->fetch_assoc()) {
while ($row = mysql_fetch_assoc($result)) {
echo " <tr>
<td>
$row['name']
</td>
</tr>";
}
echo '</tbody>
</table>';
}

Laravel/Livewire Nested Input Fields Disappear on Page Load

I am brand new to Livewire/Jetstream and trying to make a little inventory application to try it out. In my example below I'm trying to show inventory items from DB on a table with the ability to update the inventory name and quantity from the table without going to an edit page.
I have a nested foreach and when I render the page the input fields in the loop show the value and then disappear but the value is showing correctly in the HTML. Any help would be appreciated!
**Show Inventory**
namespace App\Http\Livewire;
use App\Models\Inventory;
use Livewire\Component;
class ShowInventory extends Component
{
public $inventories;
public function mount()
{
$this->inventories = Inventory::orderBy('name')->get();
}
public function render()
{
return view('livewire.show-inventory');
}
public function name()
{
$this->name = $name;
}
public function update($id)
{
$data = $this->validate([
'name' => 'required',
'available_on_hand' => 'required',
]);
$this->item_id = $id;
$item = Inventory::find($this->item_id);
$item->update([
'name' => $this->name,
'available_on_hand' => $this->available_on_hand,
]);
}
}
**Show Item**
namespace App\Http\Livewire;
use App\Models\Inventory;
use Livewire\Component;
class ShowItem extends Component
{
public $inventory;
public function mount(Inventory $inventory)
{
$this->inventory = $inventory;
}
public function render()
{
return view('livewire.show-item');
}
}
**Parent Blade**
<table class="table-auto">
<thead>
<tr>
<th>Name</th>
<th>Quantity</th>
<th></th>
<th>View</th>
</tr>
</thead>
<tbody>
#foreach($inventories as $inventory)
#livewire('show-item', ['inventory' => $inventory], key($inventory->id))
#endforeach
</tbody>
</table>
**Nested Blade**
<form wire:submit.prevent="update({{ $inventory->id }})">
<tr>
<td><input type="input" wire:model="name" value="{{$inventory->name}}" /></td>
<td><input type="input" wire:model="available_on_hand" value="{{$inventory->available_on_hand}}" /></td>
<td><button type="submit">Save</button></td>
<td>View</td>
</tr>
</form>
<form wire:submit.prevent="update({{ $inventory->id }})">
<tr>
<td><input type="input" wire:model="name"/></td>
<td><input type="input" wire:model="available_on_hand"/></td>
<td><button type="submit">Save</button></td>
<td>View</td>
</tr>
</form>
in component
public $name, $available_on_hand;
//....
public function getModel($modelID)
{
$model = Inventory::find($modelID);
$this->name = $model->name;
$this->available_on_hand = $model->available_on_hand;
}
as you can see, always you call the getModel method, it bind to your properties the current values of model also you can edit them and save it.
You can't use both, value attribute and the wire:model, that give you the conflicts you have now

Codeigniter anchor tag hyperlinked to a form in controller but the data shown outside the table

I am using Codeigniter 3 and trying CRUD operation. I have created the basic crud operation and am showing the data in a table however I have linked a paragraph tag in the controller below the table to the form controller, If I want to enter another data
The issue is when I click on the link to enter another data it redirect me the original form in controller but when I enter the data and submit it, The data is shown below the table in the paragraph tag.
I am not able understand why this is happening as the controller is the same
I had faced a similar issue before when redirecting in controller.I had redirected the page after submission to show_form() controller which was basically redirecting the page to $this->load->view('learn/view_form');
in which I have kept a condition that if No data is present click to enter. Now when it redirects to show_form() controller it goes into else condition even if the data is present
CONTROLLER
<?php
defined('BASEPATH') OR exit("No direct script access allowed");
class Learning extends CI_Controller{
public function __construct(){
parent::__construct();
$this ->load->helper("url");
$this->load->model("tatti_test");
$this->load->database();
$this->load->helper();
}
//functions should be passed here
//creating a function
function start_learn() {
//this varible
$this->load->view('learn/start_learn');
}
function start_crud(){
$this->load->view('learn/form');
}
function show_form(){
$this->load->view("learn/view_form");
}
function insert_form(){
$name = $this->input->post("u_name");
$email = $this->input->post("u_email");
$mobile = $this->input->post("u_mobile");
//File Uploading
$config['upload_path']="./assets/images/";
$config["allowed_types"]="gif|jpg|png";
$config['encrypt_name']=true;
$this->load->library("upload",$config);
if(!$this->upload->do_upload("u_file")){
$file='noimage.png';
}
else {
$filework = $this->upload->data();
$file =$filework['file_name'];
}
$data = array(
"name"=>$name,"email"=>$email,"mobile"=>$mobile,"file_name"=>$file
);
$this->tatti_test->insert_tatti($data);
redirect("learning/view_form");
}
function view_form(){
$data['returned_data']=$this->tatti_test->show_form();
$this->load->view("learn/view_form",$data);
}
function delete_entry(){
$id=$this->uri->segment(3);
$data=$this->tatti_test->for_unlink($id);
$filepath="./assets/images/".$data['file_name'];
unlink($filepath);
$this->tatti_test->delete_entry($id);
redirect('learning/view_form');
}
function time_to_update(){
$id=$this->uri->segment(3);
$data['fetched_update_entry']=$this->tatti_test->update_entry($id);
$this->load->view("learn/update.php",$data); //bus associative array hi leta hai
}
function up_db(){
$name =$this->input->post('up_name');
$email = $this->input->post('up_email');
$mobile = $this->input->post('up_mobile');
$file = $this->input->post('up_file');
$id = $this->input->post('up_id');
//File Uploading
$config['upload_path']="./assets/images/";
$config["allowed_types"]="gif|jpg|png";
$config['encrypt_name']=true;
$this->load->library("upload",$config);
if(!$this->upload->do_upload("up_file")){
$data= $this->tatti_test->remove_prev($id);
$file=$data['file_name'];
}
else {
$data= $this->tatti_test->remove_prev($id);
$path="./assets/images/".$data['file_name'];
unlink($path);
$filework = $this->upload->data();
$file =$filework['file_name'];
}
$data = array(
"name"=>$name,"email"=>$email,"mobile"=>$mobile,"file_name"=>$file
);
$this->tatti_test->up_nw($data,$id);
redirect('learning/view_form');
}
} /*this accesses command from main ci controller */
?>
VIEW
<?php $this->load->view("common/header.php");
if ($returned_data != 0){ ?>
<table border='1'>
<tr>
<th>Sr No</th>
<th>Name</th>
<th>Password</th>
<th>Mobile</th>
<th>Email</th>
<th>Final Name</th>
<th>Delete</th>
<th>View</th>
</tr>
<?php $i=0; foreach ($returned_data as $key=>$d){
?>
<tr>
<td>
<?php echo ++$i; ?>
</td>
<td>
<?php echo $d['name'];?>
</td>
<td>
<?php echo $d['mobile'];?>
</td>
<td>
<?php echo $d['email'];?>
</td>
<td>
<?php echo $d['file_name'];?>
</td>
<td>
<img src="<?php echo base_url().'/assets/images/'.$d['file_name'];?>" width="100px" ; height="100px" />
</td>
<td>Edit</td>
<td>Delete</td>
</tr>
</table>
<p>Add another entry
<?php echo anchor("learning/start_crud"," here "); ?>
</p>
<?php } ?>
<?php } else { ?>
<p>No data to show please click
<?php echo anchor("learning/start_crud"," here "); ?>to enter</p>
<?php } ?>
<?php $this->load->view("common/footer.php");
MODEL
<?php
class Tatti_test extends CI_Model{
function insert_tatti($insert_data){
$this->db->insert("f_form",$insert_data);
}
function show_form(){
$query = $this->db->get("f_form");
$response=[];
if ($query->num_rows() > 0){
$response = $query->result_array();
}
else {
$response = 0;
}
return $response;
}
function for_unlink($id){
$this->db->where("id",$id);
$query = $this->db->get("f_form");
$response=[];
foreach ($query->result_array() as $rows){
return $response = $rows;
}
}
function delete_entry($id){
$this->db->where("id",$id);
$this->db->delete("f_form");
}
function update_entry($id){
$this->db->where("id",$id);
$query = $this->db->get("f_form");
$response = [];
if($query->num_rows() > 0 ){
foreach($query->result_array() as $rows);
$response = $rows;
}
return $response;
}
function up_nw($introduced_data,$id){
$this->db->set($introduced_data);
$this->db->where('id',$id);
$this->db->update('f_form');
}
function remove_prev($id){
$this->db->where('id',$id);
$query = $this->db->get('f_form');
$response = [];
foreach($query->result_array() as $rows){
$response=$rows;
}
return $response;
}
}
?>
This is how the data is showing when clicked on the link below table
enter image description here
You're html formatting is messed up. You should have the closing </table> outside your foreach loop or premature <table> closure.
Also moved the Add another entry link outside the foreach loop. So it only appears once, and your document format not messed up.
You can use this fixed view instead:
<?php $this->load->view("common/header.php");
if ($returned_data != 0){ ?>
<table border='1'>
<tr>
<th>Sr No</th>
<th>Name</th>
<th>Password</th>
<th>Mobile</th>
<th>Email</th>
<th>Final Name</th>
<th>Delete</th>
<th>View</th>
</tr>
<?php $i=0; foreach ($returned_data as $key=>$d){
?>
<tr>
<td>
<?php echo ++$i; ?>
</td>
<td>
<?php echo $d['name'];?>
</td>
<td>
<?php echo $d['mobile'];?>
</td>
<td>
<?php echo $d['email'];?>
</td>
<td>
<?php echo $d['file_name'];?>
</td>
<td>
<img src="<?php echo base_url().'/assets/images/'.$d['file_name'];?>" width="100px" ; height="100px" />
</td>
<td>Edit</td>
<td>Delete</td>
</tr>
<?php } ?>
</table>
<p>Add another entry
<?php echo anchor("learning/start_crud"," here "); ?>
</p>
<?php } else { ?>
<p>No data to show please click
<?php echo anchor("learning/start_crud"," here "); ?>to enter</p>
<?php } ?>
<?php $this->load->view("common/footer.php");
I realize that you are trying to do CURD,
first of all, try this to improve your code and fill the missing library of codeigniter: https://github.com/avenirer/CodeIgniter-MY_Model
For your code:
No data passed to the view in show_form(),
You should check the form submission and the conditions to load the view,
simple thing to do is follow the best practice using ready scripts,
Hope this will be useful,

To get a link from database

Hi Im currently using codeigniter, Below i have attached the complete code. As i run this Im getting data from database but i want URL field to be link.How to do that.
This is my controller:
public function ajaxsearch()
{
if(is_null($this->input->get('id')))
{
$this->load->view('input_view');
}
else
{
$this->load->model('Infomodel');
$data['Infotable']=$this->Infomodel->Infotable($this->input->get('id'));
$this->load->view('output_view',$data);
}
}
Below is the model:
class Infomodel extends CI_Model
{
function Infotable($search)
{
$query = $this
->db
->select('*')
->from('Info_table')
->like('NAME',$search)
->or_like('URL',$search)
->get();
if($query->num_rows()>0)
{
return $query->result();
}
else
{
return null;
}
}
}
and two views: one is input_view
And another is output_view:
if(!empty($Infotable ))
{
$output = '';
$outputdata = '';
$outputtail ='';
$output .= '<div class="container">
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>No</th>
<th>Name</th>
<th>Url</th>
<th>Tags</th>
</tr>
</thead>
<tbody>
';
foreach ($Infotable as $objects)
{
$outputdata .= '
<tr>
<td >'.$objects->id.'</td>
<td >'.$objects->name.'</td>
<td>'.$objects->url.'</td>
<td>'.$objects->tags.'</td>
</tr>
';
// echo $outputdata;
}
$outputtail .= '
</tbody>
</table>
</div>
</div> ';
echo $output;
echo $outputdata;
echo $outputtail;
}
else
{
echo 'Data Not Found';
}
Thanks in advance for the help.
if you mean that you want the url to be clickable by the user you can simply change this line:
<td>'.$objects->url.'</td>
to something like this:
<td>'.$objects->url.'</td>
This will create a link in the table cell that will send you to the link
Try using tag inside the table data.
<td> <a heref="'.$objects->url.'">'.$objects->url.'</a></td>

Codeigniter shopping cart, view the contents in the cart page

Adding products to my cart is working fine, but after adding product to cart its not able to view it in my view page without refreshing view page,
I tried redirect() method still no use.
How do i view my page after adding products to cart.
Any help??
my controller:
<?php
class Cart extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function addtocart($cal_id, $f_id) {
if (empty($cal_id)) {
$this->load->view('Cart_view');
}
$this->load->model('cart_model');
$product = $this->cart_model->cart_contents($cal_id, $f_id);
foreach ($product as $row) {
$name = $row->title;
$fees = $row->fees;
}
$product = array(
'id' => $cal_id,
'qty' => 1,
'price' => $fees,
'name' => $name,
);
print_r($product);
$this->cart->insert($product);
$this->load->view('Cart_view');
}
public function destroy() {
$this->cart->destroy();
}
}
?>
my model:
<?php
class cart_model extends CI_Controller
{
public function __construct() {
parent::__construct();
}
public function cart_contents($cal_id,$f_id)
{
$product=$this->db->select('*')
->from('calander')
->join('fees','calander.cal_id=fees.cal_id')
->where('fees.cal_id',$cal_id)
->where('fees.f_id',$f_id)
->get();
return $product->result();
}
}
?>
my view
<html>
<head><title></title></head>
<body>
<?php
if ($cart = $this->cart->contents()) {
?><table>
<tr>
<td>
<h3><u>Cart page</u></h3>
</td>
</tr>
<tr>
<th>course</th>
<th>Quantity</th>
<th>Price</th>
</tr>
<?php
foreach ($cart as $contents) {
?><tr>
<td><?php echo $contents['name']; ?></td>
<td><input type="text" value="<?php echo $contents['qty']; ?>"></td>
<td><?php echo $contents['price']; ?></td>
</tr>
<?php } ?>
</table> <?php
// redirect(base_url('/index.php/Cart/Cart_view'));
}
?>
</body>
</html>
I dont understand what you are trying to do. When you load your view $this->load->view('Cart_view');, it is required to pass the data array, containing all the variables into the view like this $this->load->view('Cart_view',$data); . Without data array, view cannot display data. When ever you write code atleast, make variables names in such a way that other people will be able to understand what that variable stands for. Without enough data, i am taking the liberty of modifying your code
Controller
public function addtocart($cal_id, $f_id) {
$data=array(
'view'=>''
);
if (empty($cal_id)) {
$this->load->view('Cart_view',$data);
} else {
$this->load->model('cart_model');
$product = $this->cart_model->cart_contents($cal_id, $f_id);
$data['view']='';
foreach($product as $row):
$data['view'].=' <tr>
<td>'.$row->title.'</td>
<td>'.$row->qty.'</td>
<td>'.$row->price.'</td>
</tr>';
endforeach;
$this->load->view('Cart_view',$data);
}
}
MODEL
public function cart_contents($cal_id,$f_id){
$this->db->select('*')
$this->db->from('calander')
$this->db->join('fees','calander.cal_id=fees.cal_id')
$this->db->where('fees.cal_id',$cal_id)
$this->db->where('fees.f_id',$f_id);
$query = $this->db->get();
return $query->result();
}
view
<html>
<head><title></title></head>
<body>
<table>
<tr>
<td>
<h3><u>Cart page</u></h3>
</td>
</tr>
<tr>
<th>course</th>
<th>Quantity</th>
<th>Price</th>
</tr>
<?php if($count>0){
echo $view;
}?>
</table>
</body>
</html>

Categories