I use Codeigneter and I make a search function and in my function I want run two diffrent query and I want show them in diffrent table, How I can do that Sorry I can't show the data
This is My code:
My controller
function showDetail(){
// Retrieve the posted search term.
$detailTiket = $this->input->get('ticket_id');
// Use a model to retrieve the results.
$data["result"]= $this->tracking_model->showDetail($detailTiket);
$data1["result"]= $this->tracking_model->showDetail2($detailTiket);
// Pass the results to the view.
$this->load->view('tracking/tiket_detail',$data,$data1);
}
My Model
function showDetail($detailTiket)
{
if($detailTiket==""){
$detailTiket = "";
}
$showDetailTiket=$this->db->query("My Query1");
return $detailTiketDown->result();
}
function showDetail2($detailTiket)
{
if($detailTiket==""){
$detailTiket = "";
}
$detailTiketDown=$this->db->query("My query2");
return $detailTiketDown->result();
}
My view
<table Width='800'>
<?php
foreach($data as $row){?>
<tbody>
<tr>
<td><?php echo $row->ticket_id; ?></td>
</tr>
<tr>
<td><?php echo $row->created_time; ?></td>
</tr>
<tr>
<td><?php echo $row->start_IT; ?></td>
</tr>
<tr>
<td><?php echo $row->estimasi_selesai; ?></td>
</tr>
<tr>
<td><?php echo $row->name; ?></td>
</tr>
<tr>
<td><?php echo $row->description; ?></td>
</tr>
<tr style="background-color: cyan">
<td><b><?php echo $row->Status; ?></b></td>
</tr>
</tbody>
<?php } ?>
</table>
</center>
</div>
<div>
<table Width='1000'>
<?php foreach($data1 as $rows){ ?>
<tbody>
<tr>
<td><?php echo $rows->Tgl_Waktu; ?></td>
<td><?php echo $rows->PIC; ?></td>
<td><?php echo $rows->Tracking_Ticket; ?></td>
<td><?php echo $rows->Keterangan_Ticket; ?></td>
<td><?php echo $rows->File_Pendukung; ?></td>
</tr>
</tbody>
<?php }?>
</table>
You can pass data like Associative array to view
change your controller like this
Controller:
$data["result"]= $this->tracking_model->showDetail($detailTiket);
$data["result1"]= $this->tracking_model->showDetail2($detailTiket);
// Pass the results to the view.
$this->load->view('tracking/tiket_detail',$data);
view:
Table1 :
foreach($result as $row)
{
//for first result
}
Table2:
foreach($result1 as $row1)
{
//for second result
}
Related
I want 3 elements of array to be displayed before setTimeout(30000) function and 3 elements after it;so that there is gap of 30 seconds between both the loops.But I am not getting the desired result.Following is the code:
<?php
$info=array(array("name"=>"abc",
"phone"=>"12345"),
array("name"=>"pqr",
"phone"=>"23456"),
array("name"=>"def",
"phone"=>"34567"),
array("name"=>"asd",
"phone"=>"45678"),
array("name"=>"ghj",
"phone"=>"56789"),
array("name"=>"jkl",
"phone"=>"67566"),
);
echo ( $info[0]["name"]);
?>
<body>
<table>
<tr>
<th>id</th>
<th>Name</th>
<th>phone<th>
</tr>
<?php
$i=1;
foreach ($info as $data) {
if($i==4)
{
break;
}
?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $data["name"]; ?></td>
<td><?php echo $data["phone"]; ?></td>
</tr>
<?php $i++;}?>
<script>
window.setTimeout(30000);
</script>
<?php
for($j=3;$j<6;$j++)
{
?>
<tr>
<td><?php echo $j+1; ?></td>
<td><?php echo $info[$j]["name"]; ?></td>
<td><?php echo $info[$j]["phone"]; ?></td>
</tr>
<?php } ?>
</table>
I am new to codeigniter. I have a project where Admin allots balance to its reseller. Now I want to create a button in html which provides interface to admin to increment the balance on button click. and when he increments it the value should be also updated in database. Maybe this is very simple but i couldn't do this! I think I should use ajax or Jquery both for this maybe
Below is my code for view :(want to add increment and decrement button besides the balance input )
<?php echo validation_errors(); ?>
<?php echo form_open(); ?>
<table class="table">
<tr>
<td>SIP Username</td>
<td><?php echo form_input('sip_username', set_value('sip_username', $user->sip_username)); ?></td>
</tr>
<tr>
<td>SIP Password</td>
<td><?php echo form_input('sip_password', set_value('sip_password', $user->sip_password)); ?></td>
</tr>
<tr>
<td>Key</td>
<td><?php echo form_input('key', set_value('key', $user->key), 'readonly'); ?></td>
</tr>
<tr>
<td>Allocation Block</td>
<td><?php echo form_input('allocation_block', set_value('allocation_block', $user->allocation_block)); ?></td>
</tr>
<tr>
<td>Name</td>
<td><?php echo form_input('name', set_value('name', $user->name)); ?></td>
</tr>
<tr>
<td>Reseller Email</td>
<td><?php echo form_input('email', set_value('email', $user->email)); ?></td>
</tr>
<tr>
<td>Password</td>
<td><?php echo form_password('password'); ?></td>
</tr>
<tr>
<td>Confirm password</td>
<td><?php echo form_password('password_confirm'); ?></td>
</tr>
<tr>
<td>User_Required</td>
<td><?php echo form_input('user_num', set_value('user_num', $user->user_num)); ?></td>
</tr>
<tr>
<td>Balance</td>
<td><?php echo form_input('balance', set_value('balance', $user->balance)); ?></td>
</tr>
<tr>
<td>Phone</td>
<td><?php echo form_input('phone', set_value('phone', $user->phone)); ?></td>
</tr>
<tr>
<td>Address</td>
<td><?php echo form_input('address', set_value('address', $user->address)); ?></td>
</tr>
<tr>
<td>Status</td>
<td><?php echo form_dropdown('status', array('Active' => 'Active', 'Inactive' => 'inactive', 'Delete' => 'delete'), $this->input->post('status') ? $this->input->post('status') : $user->status ); ?></td>
</tr>
<tr>
<td>Country</td>
<td><?php echo form_input('country', set_value('country', $user->country)); ?></td>
</tr>
<tr>
<td>Country Code</td>
<td><?php echo form_input('country_code', set_value('country_code', $user->country_code)); ?></td>
</tr>
<tr>
<td></td>
<td><?php echo form_submit('submit', 'Save', 'class="btn btn-primary"'); ?></td>
</tr>
</table>
<?php echo form_close();?>
The Controller :
public function edit ($id = NULL)
{
// Fetch a user or set a new one
if ($id) {
$this->data['user'] = $this->reseller_m->get($id);
count($this->data['user']) || $this->data['errors'][] = 'User could not be found';
}
else {
$this->data['user'] = $this->reseller_m->get_new();
}
// Set up the form
$rules = $this->reseller_m->rules_admin;
$id || $rules['password']['rules'] .= '|required';
$this->form_validation->set_rules($rules);
// Process the form
if ($this->form_validation->run() == TRUE) {
$data = $this->reseller_m->array_from_post(array('sip_username','sip_password','key','allocation_block','name','email','password','phone','balance','user_num','address','country','country_code','created','modified','status'));
$data['password'] = $this->reseller_m->hash($data['password']);
$key=$this->reseller_m->save($data, $id);
//here we get the last inserted record id in $last_id
$last_id = $this->db->insert_id();
//The logic to create blank rows in user table mapped to reseller_id
$values=array($this->input->post('name'),$this->input->post('country_code'),$this->input->post('allocation_block'),$this->input->post('user_num'));
$key=implode('-',$values);
$this->db->where('id',$last_id);
$this->db->update('reseller',array('key'=>$key));
for($i=1; $i<=$data['user_num'];$i++)
{
$userdata=array('key'=>$key);
// here users is taken name of user table with retailer_id is field
$this->db->insert('users',$userdata);
}
redirect('admin/reseller');
}
// Load the view
$this->data['subview'] = 'admin/reseller/edit';
$this->load->view('admin/_layout_main', $this->data);
}
If you are familiar with ajax, you can use ajax for this.
On click of the button you can call ajax and write code in the controller function to update the value in the database.
Having issues displaying all of the selected data entries inside SELECT. Right now the only one that is displaying is the recipe_direct data. Each table data should list in one row the name, ingred, direct, auth name and auth email.
<div class="starter-template">
<h1>Recipes</h1>
</div>
<?php
try
{
$sql = 'SELECT recipe_id, recipe_name, recipe_ingred, recipe_direct, author_name, author_email FROM recipes';
$result = $pdo->query($sql);
}
catch (PDOException $e)
{
$error = 'Error fetching recipes: ' . $e->getMessage();
}
while ($row = $result->fetch())
{
$recipes[$row['recipe_id']] = $row;
}
?>
<p>Add a Recipe</p>
<?php foreach ($recipes as $id => $recipe): ?>
<blockquote>
<table class="table table-striped">
<tr>
<td><?php echo $recipe['recipe_name']; ?></td>
<td><?php echo $recipe['recipe_ingred']; ?></td>
<td><?php echo $recipe['recipe_direct']; ?></td>
<td><?php echo $recipe['author_name']; ?></td>
<td><?php echo $recipe['author_email']; ?></td>
</tr>
<?php htmlout($recipe_html); ?> |
edit |
delete
</table>
</blockquote>
<?php endforeach; ?>
You overwrite $recipe_html each time you assign a value to it
why not just echo out the table rows:
<table>
<?php foreach ($recipes as $id => $recipe): ?>
<tr>
<td><?= $recipe['recipe_name']; ?></td>
<td><?= $recipe['recipe_ingred']; ?></td>
<td><?= $recipe['recipe_direct']; ?></td>
<td><?= $recipe['author_name']; ?></td>
<td><?= $recipe['author_email']; ?></td>
</tr>
<?php endforeach; ?>
</table>
EdIt as #Fred -ii- states, the table tags should be outside the loop
Everything looks correct up until your foreach.
<blockquote>
<table class="table table-striped">
<?php foreach ($recipes as $id => $recipe): ?>
<tr>
<td><?php $recipe_html = $recipe['recipe_name']; ?></td>
<td><?php $recipe_html = $recipe['recipe_ingred']; ?></td>
<td><?php $recipe_html = $recipe['recipe_direct']; ?></td>
<td><?php $recipe['author_name']; ?></td>
<td><?php $recipe['author_email']; ?></td>
</tr>
<p> //seems you were missing opening <p> tag//
<?php htmlout($recipe_html); ?> |
edit | //can use shorthand here//
delete //can use shorthand here//
</p>
<?php endforeach; ?>
</table>
</blockquote>
I am working on a xml to table project which would use PHP.
<? $xml = new SimpleXMLElement('http://example.com/genXML.php?product=388', 0, TRUE);
?>
<table>
<thead>
<tr>
<th>Symbol</th>
<th>Name</th>
<th>Price</th>
<th>Change</th>
<th>Percentage</th>
<th>High</th>
<th>Low</th>
</tr>
</thead>
<tbody>
<?php foreach ($xml->product as $check) :?>
<tr>
<td><?php echo $check->symbol; ?></td>
<td><?php echo $check->name->chinese; ?></td>
<td><?php echo $check->price; ?></td>
<td><?php echo $check->change; ?></td>
<td><?php echo $check->pct_change; ?></td>
<td><?php echo $check->high; ?></td>
<td><?php echo $check->low; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
As product will have their own unique code, I would like the programe to show all the details in one table.
Is it possible to use MYSQL Database to store the product code that i need to ref. and show them out on a single web page? Thanks!
hey guys i am new in codeigniter and i am working on an application in which i have database and many records in database..i make a search form in which i make a text field in which user can fill any field value and search records.but here is a small problem..when i fill a name in textbox and click on search button no record display on view . . pls help me . . thanks ..
my controller is:
function search()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('inputsearch', 'Search Your Text Here','required');
if ($this->form_validation->run() == TRUE)
{
$this->load->helper('form');
$this->load->helper('html');
$search_this=$this->input->post('inputsearch');
$this->load->model('mod_user');
$searchmember=$this->mod_user->search_member($search_this);
$data['searchmember'] = $searchmember;
var_dump($searchmember);
$this->load->view('view_home',$data);
$this->load->view('view_homemember',$data);
}
else
{
redirect('ctl_home');
}
}
view is:
<form class="userinfo" action="" method="post">
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td width="5%;"> </td>
<td width="5%;"> </td>
<td width="15%;">Name</td>
<td width="15%;">Moderator Name</td>
<td width="20%;">KCC Branch</td>
<td width="15%;">Father/Husband Name</td>
<td width="15%;">Address</td>
<td width="10%;">Date</td>
</tr>
<?php foreach ($rows as $row):?>
<tr>
<td><?php echo anchor("Ctl_Home/edit_member/" . $row->member_id, 'Edit'); ?></td>
<td>Delete</td>
<td><?php echo $row->member_name; ?></td>
<td><?php echo $row->moderator_name; ?></td>
<td><?php echo $row->branch_name; ?></td>
<td><?php echo $row->father_name; ?></td>
<td><?php echo $row->address; ?></td>
<td><?php echo $row->date; ?></td>
</tr>
<?php endforeach; ?>
</table>
</form>
my model is:
function search_member($search_this)
{
$query=$this->db->query("SELECT tbl_members.* , tbl_moderators.member_id AS moderator_id, tbl_moderators.member_name AS moderator_name, tbl_moderators.member_no AS moderator_no, tbl_branches.branch_name FROM tbl_members, tbl_members AS tbl_moderators, tbl_branches WHERE tbl_members.moderator_id = tbl_moderators.member_id AND tbl_branches.branch_id = tbl_members.kcc_branch
AND CONCAT(tbl_members.member_name, ' ', tbl_moderators.member_name, ' ',tbl_members.moderator_id, ' ', tbl_moderators.member_id, ' ',tbl_branches.branch_name, ' ',tbl_members.father_name, ' ',tbl_members.address, ' ',tbl_moderators.address, ' ',tbl_members.date, ' ',tbl_moderators.date) like '%".$search_this."%'");
if ($query->num_rows >= 0)
{
foreach($query->result_array() as $row)
{
$data[]=$row;
}
return $data;
}
}
Your loop should have been like this
<?php foreach ($searchmember as $row):?>
<tr>
<td><?php echo anchor("Ctl_Home/edit_member/" . $row->member_id, 'Edit'); ?></td>
<td>Delete</td>
<td><?php echo $row->member_name; ?></td>
<td><?php echo $row->moderator_name; ?></td>
<td><?php echo $row->branch_name; ?></td>
<td><?php echo $row->father_name; ?></td>
<td><?php echo $row->address; ?></td>
<td><?php echo $row->date; ?></td>
</tr>
<?php endforeach; ?>
It is $searchmember as $row instead of $rows as $row in foreach
If $data['searchmember'] contains value in controller,
you can access the varibale in view as $searchmember