I use codeignIter. I use this code in view, why the window is not get close when I get click. I use this function
function setproduct(id,partno,nama,qtyscpend,ketsc,index) {
var check=0;
for (i=0;i<window.opener.$("#txtNoOfRow").val();i++) {
if (id==window.opener.$("#ids_"+i).val()) {
alert("Data Sudah Anda Pilih");
check=1;
}
}
if (check == 0){
window.opener.document.getElementsByName("ids_"+index)[0].value = id;
window.opener.document.getElementsByName("partno_"+index)[0].value = partno;
window.opener.document.getElementsByName("partname_"+index)[0].value = nama;
window.opener.document.getElementsByName("qtyscpend_"+index)[0].value = qtyscpend;
window.opener.document.getElementsByName("ketsc_"+index)[0].value = ketsc;
window.close();
}
}
Then this for show data:
<?php
$no = 1;
foreach($query->result() as $row) {?>
<tr class="even gradeA">
<td><?php echo $no ;?></td>
<td><?php echo $row->partno;?></td>
<td><?php echo $row->partname;?></td>
<td><?php echo $row->perpo;?></td>
<td><?php echo date('d F Y',strtotime($row->sched)); ?></td>
<td><?php echo $row->qtyscpend;?></td>
<td><?php echo $row->ketsc;?></td>
<td align="center">Pilih</td>
</tr>
<?php
$no++;
}
?>
What I want is when I click that align, the windows form is closed and send the variable like I wrote.
Javascript can only close those windows that were previously open with script, it is a security precaution.
https://developer.mozilla.org/ru/docs/Web/API/Window/close
Related
I am trying to change the background color of the text with a given condition. When the condition is met, the color will be changed. Here is the code I used But I got nothing in return. I tried to echo the color to see the color variable is working or not. Still, I got nothing. What is the problem here? Thanks in advance.
<?php
while($row = mysqli_fetch_assoc($result1)) {
$dersevrakno =$row['Enstitu_KararNo'];
$bolum = $row['EABD_EvrakNo'];
$status = $bolum ? $bolum : NULL; //it says $bolum is empty = $status ( not sure its correct)
if(empty($dersevrakno) && $row['OgrenciNo'] == $user_studentid){
while ($status){
$color ="blue";
echo $color; // to see $color is working or not
}
?>
<tr>
<td><?php echo $row["formgonderme"]; ?></td>
<td><?php echo $row["O_AdiSoyadi"]; ?></td>
<td><?php echo $row["OgrenciNo"]; ?></td>
<td><?php echo $row["Derece"]; ?></td>
<td width="4%" style="background-color:<?php echo $color;?>">
Bölüm Sekreterliği</td></tr>
<?php
}
}
?>
The issue that you are having is that you have an extra double " quote in your style.
Updated code:
<td width="4%" style="background-color:<?php echo $color;?>">
I can also recommend that you use a class so you can update different properties on the element with only it and you can used it on different tables and have the same consistent format.
Update to address if/while:
if(!empty($dersevrakno) && $row['OgrenciNo'] == $user_studentid && !empty($status)){
$color ="blue";
echo $color; // to see $color is working or not
}else{
// set a default color
$color="white";
}
I just changed the order of the code and now it works
<?php
while($row = mysqli_fetch_assoc($result1)) {
$dersevrakno =$row['Enstitu_KararNo'];
$bolum = $row['EABD_EvrakNo'];
$status = $bolum ? $bolum : NULL;
if ($status){
$color ="red";
}
if(empty($dersevrakno) && $row['OgrenciNo'] == $user_studentid){
?>
<tr>
<td><?php echo $row["formgonderme"]; ?></td>
<td><?php echo $row["O_AdiSoyadi"]; ?></td>
<td><?php echo $row["OgrenciNo"]; ?></td>
<td><?php echo $row["Derece"]; ?></td>
<td width="4%" style="color:<?php echo $color;?>">Bölüm Sekreterliği</td>
<?php
}
}
?>
You have an " at the end.
The next point is, have a look on "DOM" elements and how to work with them. Probably it will open your mind of how to change active elements on a page.
This is View file. I am trying to pass- "$row['ISBN'] . ':SearchByAuthor:' . $Author"- abc:SearchByAuthor:aka - value to function increment_author to controller file.
<?php
?>
<tr>
<td><?php
echo $row['ISBN'];
?></td>
<td><?php
echo $row['name'];
?></td>
<td><?php
echo $row['title'];
?></td>
<td><?php
echo $row['year'];
?></td>
<td><?php
echo $row['price'];
?></td>
<td><?php
echo $row['publisher'];
?></td>
<td><?php
echo $row['number'];
?></td>
<td> <a href="<?php
echo base_url();
?>/increment_author/<?php
echo $row['ISBN'] . ':SearchByAuthor:' . $Author;
?>">
Add to cart</a></td>
</tr>
<?php
?>
This is contoller file and I am doing some calculations and trying the same to return to above search page, which is view. However, it's not working. I am trying to convert native php code to codeIgniter framework. Please help me out in passing parameters from Controller to View and vice versa. Thanks in Advance
public function increment_author($SearchByAuthor)
{
session_start();
$db = new mysqli('localhost','root','','cheapbook') or die('Error connecting to MySQL server.');
mysqli_set_charset($db, 'utf8');
if(isset($SearchByAuthor))
{
// echo $_GET['add'];
$pieces=explode(":", $SearchByAuthor);
$quantity="SELECT D.ISBN, D.title, sum(D.number) number FROM
(SELECT A.ISBN, title, number number FROM
book A, Stocks B WHERE A.ISBN='$pieces[0]' and
A.ISBN=B.ISBN)D
GROUP BY D.ISBN, D.title";
$result = mysqli_query($db,$quantity);
while($quantity_row = mysqli_fetch_array($result))
{
if($_SESSION['cart_'.$pieces[0]])
{
$chan=0;
}
else
{
$_SESSION['cart_count']+=1;
}
if($quantity_row['number']!=$_SESSION['cart_'.$pieces[0]] )
{
$_SESSION['cart_'.$pieces[0]]+=1;
$_SESSION["cartTotal"]+=1;
}
}
$data['SearchByAuthor']=$pieces[0];
}
//header("location:search_vi?SearchByAuthor=".$pieces[0]);
//$data['SearchByAuthor']=$pieces[0];
$this->load->view('search',$data);
}
You don't have to use session_start actually you should use Session Library.
Also there is a whole Database layer in CI.
Try to debug your problem in more details. Check if your $data variable contains proper result, and in your view this will be visible via $SearchByAuthor variable.
I have wrote a select query using function but it is not returning data from MySQL database... can any one help me in this regard. I'm uploading screenshots.
Here is the name of my database, 'classified'
this is conn.php file
$conn = mysql_connect('localhost','root','');
echo mysql_select_db('classified',$conn);
function to fetch record from database, 'adds' table
On index.php i've wrote this code.
include 'functions/crud_functions.php'
$adds = get_all_adds();
foreach($adds as $add) {
<tr>
<td><?php echo $add['id']; ?></td>
<td><?php echo $add['ad_title'];?></td>
<td><?php echo $add['cat_id'];?></td>
<td><?php echo $add['ad_description'];?></td>
<td><?php echo $add['avatar'];?></td>
<td><?php echo $add['price'];?></td>
<td><?php echo $add['contact'];?></td>
<td><?php echo $add['name'];?></td>
<td><?php echo $add['time'];?></td>
<td>Edit | Del </td>
</tr>
but this is not displaying records.
Change :
if ($result) {
return TRUE;
} else {
return FALSE;
}
into this :
if ($result) {
return $data;
} else {
return array();
}
I have created custom plugin in wordpress for get data from the database. And I have added two link to perfrom action on records .One is Edit and another is Delete. I have written code for delete link like this
Delete
When I click on delete link it will show error like
You do not have sufficient permissions to access this page
My plugin code is
function submit_review()
{
add_options_page("Submit Review","Submit Reviews",1,"submit_review","submit_review");
global $wpdb;
$id = get_current_user_id();
$q = "select * from wp_submit_review where user_id = " . $id;
$result = $wpdb->get_results($q,OBJECT);
if(!empty($result))
{
?>
<div class="wrap">
<h1>Submitted Reviews</h1>
<div style="width: 100%;">
<table cellpadding="5" class="wp-list-table widefat fixed pages">
<thead>
<tr>
<th><b>Review Id</b></th>
<th><b>User Name</b></th>
<th><b>Submitted Category</b></th>
<th><b>New Listing Name</b></th>
<th><b>New Listing Address</b></th>
<th><b>New Listing City</b></th>
<th><b>New Listing Description</b></th>
<th><b>Image</b></th>
<th><b>R-option</b></th>
<th><b>New Listing Rating</b></th>
<th><b>New Listing Review</b></th>
<th><b>Actions</b></th>
</tr>
</thead>
<tbody>
<?php
foreach($result as $res)
{
?>
<td><?php echo $res->review_id; ?></td>
<td><?php echo get_the_author_meta('user_login',$res->user_id); ?></td>
<td><?php
if($res->submit_category == 1)
{
echo "Service";
}
else if($res->submit_category == 2)
{
echo "Restaurant";
}
else
{
echo "Product";
}
?>
</td>
<td><?php echo $res->newlistingname; ?></td>
<td><?php echo $res->newlistingaddress; ?></td>
<td><?php echo $res->newlistingcity; ?></td>
<td><?php echo $res->newlistingdesc; ?></td>
<td><img src="<?php echo home_url()."/uploads/".$res->image; ?>" height="50px" width="50px"/></td>
<td><?php echo $res->roption; ?></td>
<td><?php echo $res->newlistingrating; ?></td>
<td><?php echo $res->newlistingreview; ?></td>
<td>Edit | Delete</td>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<?php
}
else
{
echo "No review find";
}
}
function delete_my_review()
{
echo $_GET['id'];
}
add_action("admin_menu","delete_my_review");
function submit_review_menu()
{
add_menu_page("Submit Review","Submit Review","manage_options","submit_review", submit_review);
}
//add_action("admin_menu","submit_review");
add_action("admin_menu","submit_review_menu");
So how to call delete_my_review() function to perform delete action?
simply create a function with ajax and php. following example worked for me.
html delete button
<td><button onclick="delete_ab(<?php echo $results->id; ?>)">Delete</button></td> // pass your id to delete
javascript function
function delete_ab(str)
{
jQuery.post(
// see tip #1 for how we declare global javascript variables
MyAjax.ajaxurl,
{
// here we declare the parameters to send along with the request
// this means the following action hooks will be fired:
// wp_ajax_nopriv_myajax-submit and wp_ajax_myajax-submit
action : 'myajax_submit',
// other parameters can be added along with "action"
postID : str
},
function(response)
{
document.getElementById(str).style.display='none';
}
);
}
main function in php
function myajax_submit() {
// get the submitted parameters
$postID = $_POST['postID'];
global $wpdb;
$qry=$wpdb->query("DELETE FROM `price_table` WHERE id=$postID");
// generate the response
echo "hello";
// IMPORTANT: don't forget to "exit"
exit;
}
I have a table which is fed dynamically from the database, this works as it should, I've then put the datatables functionality on the top which is working well, the sorting, search, the pagination is again working as it should.
I'm now looking at being able to edit a row and update the data back into the db and refresh the table.
My table structure
<table class="table table-striped table-hover table-bordered" id="tobebookedtable">
<thead>
<tr>
<th style="display:none;">PropID</th>
<th>ProjectNo</th>
<th>Householder</th>
<th>HouseNoName</th>
<th>Street Name</th>
<th>Postcode</th>
<th>Telephone</th>
<th>EPCPlanned</th>
<th>TAM</th>
</tr>
</thead>
<tbody>
<tr>
<?php
$planning = db::getInstance()->query('CALL sp_tobebooked()');
foreach ($planning->results() as $planning) {
?>
<td style="display:none;"><?php echo $planning->PropID; ?></td>
<td><?php echo $planning->ProjectNo; ?></td>
<td><?php echo $planning->Householder; ?></td>
<td><?php echo $planning->HouseNoName; ?></td>
<td><?php echo $planning->StreetName; ?></td>
<td><?php echo $planning->Postcode; ?></td>
<td><?php echo $planning->Telephone; ?></td>
<td><?php echo $planning->EPCPlanned; ?></td>
<td><?php echo $planning->TAM; ?></td>
</tr>
<?php }; ?>
</tbody>
</table>
The EPCPlanned is the only field I want to update.
This here is my code for the jQuery side, the edit ability works, I can click into a cell and edit the record.
<script type="text/javascript">
$(document).ready(function() {
$('#tobebookedtable').dataTable( {
//"bProcessing": true,
//"bServerSide": true,
//"bJQueryUI": true,
"bPaginate": true,
"bStateSave": true
} );
/* Init DataTables */
var oTable = $('#tobebookedtable').dataTable();
/* Apply the jEditable handlers to the table */
oTable.$('td').editable( 'tobebooked_edit.php', {
"callback": function( sValue, y ) {
var aPos = oTable.fnGetPosition( this );
oTable.fnUpdate( sValue, aPos[0], aPos[1] );
//window.location.reload();
},
"submitdata": function ( value, settings ) {
console.log(value);
console.log(settings);
return {
"row_id": this.parentNode.getAttribute('id'),
"column": oTable.fnGetPosition( this )[2]
};
},
"height": "26px",
"width": "100%"
} );
} );
</script>
this is the tobebooked_edit.php
<?php
require 'core/init.php';
$table="temp_tobebooked";
$rawdata = $_POST;
$query = "show columns from $table";
$result= mysql_query($query) or die(mysql_error());
$fields = array();
while ( $row = mysql_fetch_assoc($result) )
{
$fieldname = $row['Field'];
array_push($fields, $fieldname);
}
$id = $rawdata['row_id'];
$value = $rawdata['value'];
$column = $rawdata['column'];
$column = $column + 1;
$fieldname = $fields[$column];
$value = utf8_decode($value);
$query = "update $table set $fieldname = '$value' where PropID = '$id'";
$result = mysql_query($query);
if (!$result) { echo "Update failed"; }
else { echo "UPD: $value"; }
?>
When it all runs and I update a record the field Updates on the screen and shows with the "UPD:" and the entered value.
But when I check my database there is no record updated. No errors show either
How can I get the data to update in my db?
First of all, I think that this
<tr>
<?php
$planning = db::getInstance()->query('CALL sp_tobebooked()');
foreach ($planning->results() as $planning) {
?>
should be
<?php
$planning = db::getInstance()->query('CALL sp_tobebooked()');
foreach ($planning->results() as $planning) {
?>
<tr>
Then, with
"row_id": this.parentNode.getAttribute('id'),
for each td element, you select the tr element and search for the id attribute, that doesn't exists
Firstly as per rsella's comment you nee to move the row inside the loop.
Secondly as suspected you are holding the ID in a hidden cell which is infact a sibling of the editable elements rather than the parent. Try changing the table structure to the following
<tbody>
<?php
$planning = db::getInstance()->query('CALL sp_tobebooked()');
foreach ($planning->results() as $planning) {
?>
<tr id="<?php echo $planning->PropID; ?>" >
<td><?php echo $planning->ProjectNo; ?></td>
<td><?php echo $planning->Householder; ?></td>
<td><?php echo $planning->HouseNoName; ?></td>
<td><?php echo $planning->StreetName; ?></td>
<td><?php echo $planning->Postcode; ?></td>
<td><?php echo $planning->Telephone; ?></td>
<td><?php echo $planning->EPCPlanned; ?></td>
<td><?php echo $planning->TAM; ?></td>
</tr>
<?php };
?>
</tbody>
This should mean that the parent has an ID and thus this.parentNode.getAttribute('id') should be able returning the required value.
As you're only editing the EPCPlanned cell then an alternative would be
<tbody>
<?php
$planning = db::getInstance()->query('CALL sp_tobebooked()');
foreach ($planning->results() as $planning) {
?>
<tr>
<td><?php echo $planning->ProjectNo; ?></td>
<td><?php echo $planning->Householder; ?></td>
<td><?php echo $planning->HouseNoName; ?></td>
<td><?php echo $planning->StreetName; ?></td>
<td><?php echo $planning->Postcode; ?></td>
<td><?php echo $planning->Telephone; ?></td>
<td id="<?php echo $planning->PropID; ?>"><?php echo $planning->EPCPlanned; ?></td>
<td><?php echo $planning->TAM; ?></td>
</tr>
<?php };
?>
</tbody>
and in your JQuery change "row_id": this.parentNode.getAttribute('id') to this.getAttribute('id')