I am trying to automate the hallticket process for an institution. This includes a certain verification process.
Iframe is working only for the first row, what should I do to open it for multiple rows based on the row selection
php code
<?php
while($row = mysqli_fetch_assoc($rows)) //Retriving the rows from the database
{
?>
<td><?php echo $app_id ?></td>
<td><?php echo $first_name ?></td>
<td><?php echo $last_name ?></td>
<td><?php echo $email_id ?></td>
<td><?php echo $mobile_number ?></td>
<td><?php echo $dd_number ?></td>
<td><?php echo $course_name ?></td>
<?php
if($dd_submit==1 && $ht_sent==0)
{?>
<td class="verified"><span>Verified</span></td>
<?php }elseif($dd_submit==0 && $ht_sent==0){ ?>
<td class="non_verified"><span>None Verified</span></td>
<?php }else{ ?> <td class="Pending"><span>Hall Ticket Sent</span></td>
<?php } ?>
<!-- I think the problem is here the java script is not repeating -->
<td><button id="dialog" name="verify" value="<?php echo $row['app_id'] ?>" > <img src="images/success_tick.png"></button><img src="images/meassage_table.png"><img src="images/comment.png"></td>
</tr>
<?php
}
?>
<div id="dialogContent" title="DD Verification for Vinay Draksharam">
<iframe src='ddverification_page.php?app_id=<?php echo $app_id ?> '></iframe>
Java Script
<script>
$(function () {
$("#dialogContent").dialog({
autoOpen: false,
modal: true
});
$('#dialog').click(function () {
$("#dialogContent").dialog( "open" );
});
});
</script>
First problem- you have many rows but you only create one dialog. You probably have to put dialog creation inside loop to have separate dialog for each row. You also need some way to create connection between dialog and row. Best idea would probably to use $app_id as id of dialog.
What i would do:
PHP:
<?php
while($row = mysqli_fetch_assoc($rows)) //Retriving the rows from the database
{
?>
<td><?php echo $app_id ?></td>
<td><?php echo $first_name ?></td>
<td><?php echo $last_name ?></td>
<td><?php echo $email_id ?></td>
<td><?php echo $mobile_number ?></td>
<td><?php echo $dd_number ?></td>
<td><?php echo $course_name ?></td>
<?php
if($dd_submit==1 && $ht_sent==0)
{?>
<td class="verified"><span>Verified</span></td>
<?php }elseif($dd_submit==0 && $ht_sent==0){ ?>
<td class="non_verified"><span>None Verified</span></td>
<?php }else{ ?> <td class="Pending"><span>Hall Ticket Sent</span></td>
<?php } ?>
<!-- I think the problem is here the java script is not repeating -->
<td><button class="dialog" name="verify" value="<?php echo $row['app_id'] ?>" >
<div class="dialogContent" id="dialogContent_<?php echo $app_id ?>" title="DD Verification for Vinay Draksharam">
<iframe src='ddverification_page.php?app_id=<?php echo $app_id ?> '></iframe> </div>
<img src="images/success_tick.png"></button><img src="images/meassage_table.png"><img src="images/comment.png"></td>
</tr>
<?php
}
?>
And Javascript:
$(function () {
$(".dialogContent").dialog({
autoOpen: false,
modal: true
});
$('.dialog').click(function () {
$("#dialogContent_"+$(this).val()).dialog( "open" );
});
});
Related
I want to load another view using the function within the same controller. I'm new to codeIgniter so Please go easy on me :D
loaded home page by default -> From Home page filled in fields -> submit -> using ajax grabbed data from database -> use data on another page by loading the new view in the same controller as the default.
Controller:
<?php
class logInCon extends CI_Controller
{
public function login()
{
//$data['creds'] = $this->accsModel->getUser();
$this->load->view("Login");
}
public function validate_LogIn()
{
$uname = $this->input->post('uname');
$pass = $this->input->post('pass');
$this->load->model("accsModel");
$data = $this->accsModel->logInCheck($uname, $pass);
$check = $data['verified'];
if ($check <= 0)
{
echo "Not a valid member";
}else
{
$data['logged'] = $this->accsModel->getUser($uname, $pass);
$this->load->view('comms.php');//want this to load
}
}
}
?>
Model
<?php
/**
*/
class accsModel extends CI_Model
{
public function getBps()
{
$query = $this->db->get('bps');
return $query->result();
}
public function getUser($uname, $psswrd)
{
$getCreds = $this->db->query("SELECT `bps`.*, `users`.bps_id
FROM `bps`
LEFT JOIN `users`
ON `bps`.id = `users`.bps_id
AND `users`.`uname` = '$uname'
AND `users`.`pwd` ='$psswrd'
WHERE `users`.bps_id != ''
OR `users`.bps_id IS NOT NULL");
return $getCreds->result();
}
public function logInCheck($uname, $psswrd)
{
$this->db->select('COUNT(*) AS verified');
$this->db->where('uname', $uname);
$this->db->where('pwd', $psswrd);
$this->db->limit(1);
return $this->db->get('users')->row_array();
}
}
?>
View
<body>
<div class="container">
<div class="row">
<div class="LogForm">
<div class="col-md-12">
<input type="text" id="bpCode" name="bpCode">
</div>
<div class="col-md-12">
<input type="password" id="pass" name="pass">
</div>
<div class="btn">
<span id="emptyF" hidden style="color:red;"></span>
<button id="submit" class="btn btn-info btn-lg btn-block">Login</button>
<span id="result"></span>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function()
{
$("#submit").click(function()
{
var uname = $('#bpCode').val();
var pass = $('#pass').val();
if(uname == "" || pass =="")
{
$("#emptyF").attr("hidden", false).html("Please fill in the form");
}else{
$("#emptyF").attr("hidden", true);
$.ajax({//start of ajax function
type: "POST",
url: "<?php echo base_url('logInCon/validate_LogIn'); ?>",
data:
{
uname : uname,
pass : pass
}
//end of ajax function
});
}
});
});
</script>
</body>
View comms want this to be loaded and use the the data from the getUser() function
<body>
<p><?php print_r($logged) ?></p>
<h1>Commissions View</h1>
<table style="width:100%">
<?php
foreach ($logged as $lgdIn) {
?>
<tr>
<th>ID</th>
<th>bpID</th>
<th>pc</th>
<th>up</th>
<th>tmLdr</th>
<th>fName</th>
<th>mName</th>
<th>lName</th>
<th>contactNo</th>
<th>Status-Id</th>
<th>bpclass_id</th>
</tr>
<tr>
<td><?php echo $lgdIn->id; ?></td>
<td><?php echo $lgdIn->bpID; ?></td>
<td><?php echo $lgdIn->pc; ?></td>
<td><?php echo $lgdIn->up; ?></td>
<td><?php echo $lgdIn->tmLdr; ?></td>
<td><?php echo $lgdIn->fName; ?></td>
<td><?php echo $lgdIn->mName; ?></td>
<td><?php echo $lgdIn->lName; ?></td>
<td><?php echo $lgdIn->contactNo; ?></td>
<td><?php echo $lgdIn->status_id; ?></td>
<td><?php echo $lgdIn->bpclass_id; ?></td>
</tr>
<?php
}
?>
</table>
</body>
You need to pass $data in load view just like below code
public function validate_LogIn()
{
$uname = $this->input->post('uname');
$pass = $this->input->post('pass');
$this->load->model("accsModel");
$data = $this->accsModel->logInCheck($uname, $pass);
$check = $data['verified'];
if ($check <= 0)
{
echo "Not a valid member";
}else{
$data['logged'] = $this->accsModel->getUser($uname, $pass);
$this->load->view('comms',$data);//want this to load
}
}
little change in view too
<body>
<p><?php print_r($logged) ?></p>
<h1>Commissions View</h1>
<table style="width:100%">
<tr>
<th>ID</th>
<th>bpID</th>
<th>pc</th>
<th>up</th>
<th>tmLdr</th>
<th>fName</th>
<th>mName</th>
<th>lName</th>
<th>contactNo</th>
<th>Status-Id</th>
<th>bpclass_id</th>
</tr>
<?php if(!empty($logged)) { foreach ($logged as $lgdIn) { ?>
<tr>
<td><?php echo $lgdIn->id; ?></td>
<td><?php echo $lgdIn->bpID; ?></td>
<td><?php echo $lgdIn->pc; ?></td>
<td><?php echo $lgdIn->up; ?></td>
<td><?php echo $lgdIn->tmLdr; ?></td>
<td><?php echo $lgdIn->fName; ?></td>
<td><?php echo $lgdIn->mName; ?></td>
<td><?php echo $lgdIn->lName; ?></td>
<td><?php echo $lgdIn->contactNo; ?></td>
<td><?php echo $lgdIn->status_id; ?></td>
<td><?php echo $lgdIn->bpclass_id; ?></td>
</tr>
<?php } } else { ?>
<tr colspan="11"><td>No record found.</td></tr>
<?php } ?>
</table>
</body>
Can I able to retrieve the string value of a link and put it in the textbox on different PHP page? I'm using my first column as the link.
Like this:
<tr>
<td><?php echo $row['Control_Num']; ?></td>
<td><?php echo $row['Date_Req'];?></td>
<td><?php echo $row['Date_Rev'];?></td>
<td><?php echo $row['Rev_by'];?></td>
<td><?php echo $row['Requester'];?></td>
<td><?php echo $row['Dept'];?></td>
<td><?php echo $row['email'];?></td>
<td><?php echo $row['cont_num'];?></td>
<td><?php echo $row['serv_req'];?></td>
<td><?php echo $row['purpose'];?></td>
<td><?php echo $row['app_by'];?></td>
</tr>
This is href link "http://www.example.com" which you want to redirect that
<script>
var burl = "http://www.example.com";
</script>
<p> textstring</p>
retrieve the string value of a link
<script>
(function() {
Array.prototype.forEach.call(document.querySelectorAll("a.burl"),
function(link) {
link.href = burl + link.getAttribute("data-extra");
});
})();
</script>
I want to display data in single foreach loop. I have two tables dailystats and monthlystats both of them have same columns like calls,minutes,incomingcalls etc Im using Yii PHP Framework Here is my controller
public function actionViewStats(){
$model = new Company();
$id = $_GET['id'];
$modelMonthly = $model->getCompanyUsageMonthly($id);
$modelDaily = $model->getCompanyUsageDaily($id);
$this->renderPartial('/shared/_company_stats', array(
'modelDaily' => $modelDaily,
'modelMonthly'=>$modelMonthly
));
}
Here is my view of table.
<?PHP if(isset($modelMonthly) && sizeof($modelMonthly)!=0): ?>
<div class="ibox-content col-md-12 col-xs-12">
<div class="title col-md-2">
<h3>Current Usage</h3>
</div>
<div class="col-md-10">
<div class="col-md-12 col-xs-12">
<table class="table">
<thead>
<th>Minutes</th>
<th>Incoming Minutes</th>
<th>Calls</th>
<th>Incoming Calls</th>
</thead>
<tbody>
<?PHP
if(isset($modelMonthly)){
foreach($modelMonthly as $monthlystats){
?>
<tr>
<td><?php echo $monthlystats->minutes?></td>
<td><?PHP echo $monthlystats->incoming_minutes; ?></td>
<td><?PHP echo $monthlystats->calls; ?></td>
<td><?PHP echo $monthlystats->incoming_calls; ?></td>
</tr>
<?PHP } } ?>
</tbody>
</table>
</div>
</div>
</div>
<?PHP endif;?>
This is showing only monthly stats modelMonthly but i want to show daily stats modelDaily too in the same foreach loop.. How do i do that? I have tried array_combine etc but unable to do it. Searched on SOF but unable to find solution for it.
My code above shows only Monthly stats like this
But I want to show like this below. I have already made the table but im not able to use both modelDaily and modelMonthly in same foreach loop. I have tried different things but unable to do it..
<?PHP
if(isset($modelMonthly)){
foreach($modelMonthly as $usage){
?>
<tr>
<td><?php echo $usage->minutes?></td>
<td><?PHP echo $usage->incoming_minutes; ?></td>
<td><?PHP echo $usage->calls; ?></td>
<td><?PHP echo $usage->incoming_calls; ?></td>
</tr>
<?PHP } } ?>
If both your arrays have numerical indexes, you can use a regular for loop:
for ($i = 0; $i < max(count($modelMonthly), count($modelDaily)); $i) {
if (isset($modelDaily[$i]) {
// Add the daily columns
} else {
// Add as much empty columns
}
if (isset($modelMonthly[$i]) {
// Add the monthly columns
} else {
// Add as much empty columns
}
}
The next step is adding the required headers th in the thead, and adding the extra td inside the loop.
Alternatively, you can create both table independantly, and position them using CSS. It is not in the scope of this question, but this is what I would recommend.
You shoudl use this tecnique
foreach($modelMonthly as $index => $usage){
?>
<tr>
<td><?php echo $usage->minutes?></td>
<td><?PHP echo $usage->incoming_minutes; ?></td>
<td><?PHP echo $usage->calls; ?></td>
<td><?PHP echo $usage->incoming_calls; ?></td>
<td><?php if (isset($dailystats[$index]->minute)) echo $dailystats[$index]->minutes?></td>
<td><?PHP if (isset($dailystats[$index]->incoming_minutes)) echo $dailystats[$index]->incoming_minutes; ?></td>
<td><?PHP if (isset($dailystats[$index]->calls)) echo $dailystats[$index]->calls; ?></td>
<td><?PHP if (isset($dailystats[$index]->incoming_calls)) echo $dailystats[$index]->incoming_calls; ?></td>
</tr>
<?PHP } } ?>
I want to display based on the year with repeated first_ ids and actual ids. but actual_id is unique.
<?php while($Row=oci_fetch_assoc($Result)){
$ResultArray[$j]['First_ID']=$Row['First_ID'];
$ResultArray[$j]['Actual_ID']=$Row['Actual_ID'];
$ResultArray[$j]['Title']=$Row['Title'];
$ResultArray[$j]['START_DATE']=$Row['START_DATE'];
$startDate=explode(' ',$Row['START_DATE']);
$ResultArray[$j]['YEAR']=$startDate[0];
if(($startDate[0])==($startyear)){
$ResultArray[$j][$startyear]['Actual_ID']=$Row['Actual_ID'];
$ResultArray[$j][$startyear]['Other_ID']=$Row['Other_ID'];
$ResultArray[$j][$startyear]['Content']=$Row['Content'];
}
if(($startDate[0])==($startyear+1)){
$ResultArray[$j][$startyear+$i]['Actual_ID']=$Row['Actual_ID'];
$ResultArray[$j][$startyear+$i]['Other_ID']=$Row['Other_ID'];
$ResultArray[$j][$startyear+$i]['Content']=$Row['Content'];
}
if(($startDate[0])==($startyear+1)){
$ResultArray[$j][$startyear+$i]['Actual_ID']=$Row['Actual_ID'];
$ResultArray[$j][$startyear+$i]['Other_ID']=$Row['Other_ID'];
$ResultArray[$j][$startyear+$i]['Content']=$Row['Content'];
}
$j++;
}?>
//to display in table
it display year with asc order first and then next year etc.
<table class="tab">
<tr><th>S.No</th>
<th>first_ id</th><th>Title</th>
<?phpfor($i=0;$i<4;$i++){?><th colspan="3"><?php echo $startyear+$i; ?> </th>
<?php }?>
<tr><th></th><th></th><th></th>
<th>Actual_ID</th><th>Other_ID</th><th>Content</th>
<th>Actual_ID</th><th>Other_ID</th> <th>Content</th>
<th>Actual_ID</th><th>Other_ID</th><th>Content</th>
<th>Actual_ID</th><th>Other_ID</th><th>Content</th></tr>
<?php
foreach($ResultArray as $ResultArray1){
//print_r($abstarctResultArray1);
?><tr><td><?php echo $count; $count++;?></td>
<td><?php echo $ResultArray1['First_ID'];?></td>
<td><?php echo $ResultArray1['Title'];?></td>
<?php for($i=0;$i<4;$i++){
$startDate=explode(' ',$ResultArray1['START_DATE']);
if(($startDate[0]==$startyear)){?>
<td><?php echo $ResultArray1[$startDate[0]['Actual_ID'];?></td>
<td><?php echo $ResultArray1[$startDate[0]['Other_ID'];?></td>
<td><?php echo $ResultArray1[$startDate[0]['Content'];?></td>
<?php }
else if(($startDate[0]==$startyear+1)){?>
<td><?php echo $ResultArray1[$startDate[0]['Actual_ID'];?></td>
<td><?php echo $ResultArray1[$startDate[0]['Other_ID'];?></td>
<td><?php echo $ResultArray1[$startDate[0]['Content'];?></td>
</tr>
<?php
}
else if(($startDate[0]==$startyear+2)){?>
<td><?php echo $ResultArray1[$startDate[0]['Actual_ID'];?></td>
<td><?php echo $ResultArray1[$startDate[0]['Other_ID'];?></td>
<td><?php echo $ResultArray1[$startDate[0]['Content'];?></td>
</tr>
<?php
}
}
}
?>
I have tried with different ideas, but I can't. Please help.
I'm trying to select a particular row using jquery from a looped foreach. For now I'm just using a simple alert to see if I get the right row. Problem is, it only selects the last row, and not the row I clicked.
Example code:
<?php foreach ($customers as $c) : ?>
<tr>
<td><?php echo $count++; ?></td>
<td><?php echo $c['firstname'] . " " . $c['lastname']; ?></td>
<td><?php echo $c['phone']; ?></td>
<td><?php echo $c['email']; ?></td>
<td style="display:none" id="'<?php echo $c['id'] ?>'"> </td>
</tr>
<?php endforeach ?>
The Jquery call:
$('tr td ').click(function(){
var fn = '<?php echo $c['firstname']; ?>';
alert(fn);}
);
This will output all td values. Credits
<html>
<head>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
</head>
<body>
<?php
$count = 0;
$customers = array (
array('firstname'=>'fname1', 'lastname'=>'lname1','phone'=>'111','email'=>'a#gmail.com','id'=>1),
array('firstname'=>'fname2', 'lastname'=>'lname2','phone'=>'222','email'=>'b#gmail.com','id'=>2),
array('firstname'=>'fname3', 'lastname'=>'lname3','phone'=>'333','email'=>'c#gmail.com','id'=>3),
array('firstname'=>'fname4', 'lastname'=>'lname4','phone'=>'444','email'=>'d#gmail.com','id'=>4),
);
?>
<table class="table table-bordered">
<?php foreach ($customers as $c) : ?>
<tr class="getdetails">
<td><?php echo $count++; ?></td>
<td><?php echo $c['firstname'] . " " . $c['lastname']; ?></td>
<td><?php echo $c['phone']; ?></td>
<td><?php echo $c['email']; ?></td>
<td style="display:none" id="'<?php echo $c['id'] ?>'"> </td>
</tr>
<?php endforeach ?>
</table>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script>
$(".getdetails").click(function(){
$(this).find("td").each(function(){
console.log($(this).html());
});
});
</script>
</body>
</html>
You can access particular row's column like bellow
$('tr.item').each(function() { // selected tr
var col1 = $(this).find("td:eq(0) > input").val(); // find the input field value inside the first column of the row
var col2 = $(this).find("td:eq(1) > input").val();}