get number of selected row AJAX - ZEND - ajax

actually i have the follow code working, but it is tacking alway the first record [0]: echo $this->bills[0]['id'];, how could i change it to get the record selected with double click?
Here code for the view object in zend:
echo '<table id="tabla_listado_cuentas">';
echo '<thead>';
echo '<tr>';
echo "<th><a href=''>Id Factura</a></th>";
echo "<th><a href=''>Estado Factura</a></th>";
echo '</tr>';
echo '</thead>';
echo '<tbody>';
echo '<td id="ident">'.$bill['id'].'</td>';
echo '<td id="td_con_separacion" class="estado">'.$bill['estado']."</td>";
echo "</tr>";
echo '</tbody>';
echo '</table>';
echo '</form>';
?>
<script>
$(".estado").editable("<?php echo $this->baseUrl().'/bills/update-Ajax'?>", {
indicator : "Guardando...",
tooltip : 'Click para editar',
data : " {'payed':'Pagada','acepted':'Aceptada','pending':'Pendiente','denied':'Deniegada'}",
type: 'select',
submit: 'Ok',
event : "dblclick",
placeholder : '...',
submitdata : function(value, settings) {
return {column: "estado", estado: "<?php echo $this->bills[0]['estado']; ?>", bill: "<?php echo $this->bills[0]['id'];?>"};
}
});
</script>
Thanks a lot in advance

Related

How can we display dynamic modal popup in codeigniter 3

I am working on a Codeigniter project which displays database information in the form of cards, having an option for Read More. I want to display the modal popup with the selected row content. For now the code I'm working is displaying only the first row, and if model target is removed the code is displaying correct contents but its not showing in form of modal. Please assist with the query.
Code for view starts here
<div class="row clearfix">
<?php
$query = $this->db->query("SELECT * FROM services_offered LIMIT 15");
foreach ($query->result() as $row) {
echo "<div class='col-lg-4 bottommargin-sm'>";
echo "<div class='feature-box media-box fbox-bg'>";
echo "<div class='fbox-media'>";
echo "<a href='#'><img src='$row->swo_images' alt='Featured Box Image' style='height:250px; width:450px;'></a></div>";
echo "<div class='fbox-content fbox-content-lg'>";
$string = $row->swo_brief_intro;
$string = word_limiter($string, 15);
echo "<h3 class='nott ls0 font-weight-semibold'>$row->swo_image_heading<span class='subtitle font-secondary font-weight-light ls0'>$string</span></h3>";
echo "<a href='Fetch/getDetails/{$row->id}' class='button-link border-0 color btn-edit' data-toggle='modal' data-target='#whatwedo'>Read More</a>";
echo "</div>";
echo "</div>";
echo "</div>";
// section for modal starts here
echo "<div class='modal fade' id='whatwedo' tabindex='-1' aria-labelledby='exampleModalLabel' aria-hidden='true'>";
echo "<div class='modal-dialog'>";
echo "<div class='modal-content'>";
echo "<div class='modal-header'>";
echo "<h5 class='modal-title' id='exampleModalLabel'>$row->swo_image_heading</h5>";
echo "<button type='button' class='close' data-dismiss='modal' aria-label='Close'>";
echo "<span aria-hidden='true'>×</span>";
echo "</button>";
echo "</div>";
echo "<div class='modal-body'>";
echo "</div>";
echo "<div class='modal-footer'>";
echo "<button type='button' class='btn btn-secondary' data-dismiss='modal'>Close</button>";
echo "<button type='button' class='btn btn-primary'>Save changes</button>";
echo " </div>";
echo "</div>";
echo "</div>";
echo "</div>";
// section for modal starts here
}
?>
Code for the Controller starts here
public function getDetails($id)
{
$row = $this-> db
-> select('swo_brief_intro, swo_image_heading, swo_images')
-> where('id', $id)
-> limit(1)
-> get('services_offered')
-> row();
if (isset($row))
{
echo "<div class='modal fade' id='exampleModal' tabindex='-1' aria-labelledby='exampleModalLabel' aria-hidden='true'>";
echo "<div class='modal-dialog'>";
echo "<div class='modal-content'>";
echo "<div class='modal-header'>";
echo "<h2 class='modal-title' id='exampleModalLabel'>$row->swo_image_heading</h2>";
echo "<button type='button' class='close' data-dismiss='modal' aria-label='Close'>";
echo "<span aria-hidden='true'>×</span>";
echo "</button>";
echo "</div>";
echo "<div class='modal-body'>";
echo "<label>$row->swo_brief_intro</label>";
echo "<br />";
echo "<img src='".base_url().$row->swo_images."' class='img-fluid' alt='' style='height:250px; width:650px;'>";
echo "</div>";
echo "<br />";
echo "<div class='modal-footer'>";
echo "<button type='button' class='btn btn-secondary' data-dismiss='modal'>Close</button>";
echo "<button type='button' class='btn btn-primary'>Save changes</button>";
echo " </div>";
echo "</div>";
echo "</div>";
echo "</div>";
}
}
Please assist for the query. Thankyou
The view would be like this
but the modal is always displaying the first content
You should give the modal different ID each modal or services, ID must unique for each services.
give id for the button
echo "<a href='fetchDetails' class='button-link border-0 color btn-edit' data-toggle='modal' data-target='#idmodal'>Read More</a>";
and give the modal also the same id
echo "<div class='modal fade' id='idmodal' tabindex='-1' aria-labelledby='exampleModalLabel' aria-hidden='true'>";
you can use services id in your database or give it a unique name make sure the button and the modal have the same id.
btw I already answered this on your other question

How can we show particular images on popup modal when image is clicked in CodeIgniter?

Have displayed data from database using bootstrap card. All these cards have Read more buttons. Once click on the Read More the modal should fetch that specific row details and display.
The view is as shown below
The codes are mentioned below:
Code for View using card
<div class="row clearfix">
<?php
$query = $this->db->query("SELECT * FROM services_offered LIMIT 15");
foreach ($query->result() as $row) {
echo "<div class='col-lg-4 bottommargin-sm'>";
echo "<div class='feature-box media-box fbox-bg'>";
echo "<div class='fbox-media'>";
echo "<a href='#'><img src='$row->swo_images' alt='Featured Box Image' style='height:250px; width:450px;'></a></div>";
echo "<div class='fbox-content fbox-content-lg'>";
$string = $row->swo_brief_intro;
$string = word_limiter($string, 15);
echo "<h3 class='nott ls0 font-weight-semibold'>$row->swo_image_heading<span class='subtitle font-secondary font-weight-light ls0'>$string</span></h3>";
echo "<a href='fetchDetails' class='button-link border-0 color btn-edit' data-toggle='modal' data-target='#whatwedo'>Read More</a>";
echo "</div>";
echo "</div>";
echo "</div>";
}
?>
Code for modal that should load:
<?php
$query = $this->db->query("SELECT * FROM services_offered");
foreach ($query->result() as $row) {
echo "<div class='modal fade' id='whatwedo' tabindex='-1' aria-labelledby='exampleModalLabel' aria-hidden='true'>";
echo "<div class='modal-dialog' >";
echo "<div class='modal-content'>";
echo "<div class='modal-header'>";
echo "<h5 class='modal-title' id='exampleModalLabel'>$row->swo_image_heading</h5>";
echo "<button type='button' class='close' data-dismiss='modal' aria-label='Close'>";
echo " <span aria-hidden='true'>×</span>";
echo "</button>";
echo "</div>";
echo "<div class='modal-body'>";
echo "..";
echo "</div>";
echo "<div class='modal-footer'>";
echo "<button type='button' class='btn btn-secondary' data-dismiss='modal'>Close</button>";
echo "<button type='button' class='btn btn-primary'>Save changes</button>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
}
?>
Code for controllers
public function fetchDetails($id)
{
$this->db->where('id',$id);
$query = $this->db->query("SELECT * FROM services_offered");
return $query->result();
}
You should give the modal different ID each modal or services, ID must unique for each services.
give id for the button
echo "<a href='fetchDetails' class='button-link border-0 color btn-edit' data-toggle='modal' data-target='#idmodal'>Read More</a>";
and give the modal also the same id
echo "<div class='modal fade' id='idmodal' tabindex='-1' aria-labelledby='exampleModalLabel' aria-hidden='true'>";
you can use services id in your database or give it a unique name make sure the button and the modal have the same id.

Dynamically populated select using ajax in WordPress

I want to use the value from my first dropdown in a MySQL query to generate a second dropdown. I'm doing this in wordpress and have tried to modify code I have used for a form plugin to apply to a coded form. But the code I have doesn't populate the second dropdown.
<form id="page-changer" action="" method="post"> <?php
$chart_types = $wpdb->get_results( "SELECT page_id, title FROM master_chart WHERE mod_id=$mod_id AND (geo_type=$geo_type OR geo_type IS NULL) ORDER BY sequence" );
echo '<select id="chart_type" required style="width: 100%; margin-bottom: 15px;"><option value="" disabled selected>Select Chart Type</option>';
foreach ($chart_types as $chart_type) :
echo '<option value="'.$chart_type->page_id.'">'.$chart_type->title.'</option>';
endforeach;
echo '</select>'; ?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#chart_type').change(function(){
var chartPOP=jQuery('#chart_type').val();
jQuery('#response').empty();
jQuery.ajax({
url:"<?php bloginfo( 'wpurl' ); ?>/wp-admin/admin-ajax.php",
type:'POST',
data:'action=populate_chart&pageID=' + chartPOP,
success:function(results) {
jQuery('#response').append(results);
}
});
});
});
</script> <?php
echo '<select id="response"><option value="" disabled selected>Select Frequency</option></select>';
function populate_chart() {
if( isset( $_POST['pageID'] ) ) :
$page_id=$_POST['pageID'];
global $wpdb;
$frequencies = $wpdb->get_results( "SELECT title FROM master_chartmeta WHERE measure >= $measure_toggle AND page_id=$page_id");
foreach( $results as $rows ) :
$option .= '<option value="'.$rows->title.'">';
$option .= $rows->title;
$option .= '</option>';
endforeach;
echo $option;
die();
endif;
}
add_action( 'wp_ajax_nopriv_populate_chart', populate_chart );
add_action( 'wp_ajax_populate_chart', populate_chart );

All owl Carousel breaks after closing the Magnific popup content using ajax

i m creating a single page WP theme, actually theme is created BY some one else i am converting it to WP. all works fine but when a post from blog section is viewed and closed all the carousels breaks on the site. post opens in magnific popup.
Links:
Magnific:
$('.ajax-popup-link').magnificPopup({ type: 'ajax', closeOnBgClick: false });
Full code where I am using the popup:
<?php
$bl_args = array(
'post_type' => 'post',
'orderby' => 'date',
'order' => 'DEC',
);
$counter = 0;
$bl_query = new WP_Query( $bl_args );
if ( $bl_query->have_posts() ) {
while ( $bl_query->have_posts() ) {
$bl_query->the_post();
if ( $counter%4 == 0 ) {
echo '<div class="blog">';
echo '<div class="row">';
} // open before every fourth item
echo '<div class="col-md-6">';
?>
<a href="<?php the_permalink(); ?>" class="ajax-popup-link">
<?php the_post_thumbnail('blog-thumb'); ?>
</a>
<?php
echo '<div class="row">';
echo '<div class="col-sm-2"><span><span>';
the_time('j');
echo '</span>';
the_time('F Y');
echo '</span>';
echo '</div><!-- .col-sm-2 -->';
echo '<div class="col-sm-10">';
echo '<h4>';
?>
<a href="<?php the_permalink(); ?>" class="ajax-popup-link">
<?php echo get_the_title(); ?>
</a>
<?php
echo '</h4>';
the_excerpt();
echo '</div><!-- .col-sm-10 -->';
echo '</div><!-- .row -->';
echo '</div><!-- .col-md-6 -->';
if ( $counter%4 == 3 ) {
echo '</div><!-- .row -->';
echo '</div><!-- .blog -->';
} // close after each block of four or after last item
$counter++;
}
}
/* Restore original Post Data */
wp_reset_postdata();
The problem was because with popup, the styles and scripts were loaded again. I removed wp_head() and wp_footer() from the popup and everything works great now.

Need to set and get the value of the clicked link

The code below is the display of search result of my project. The code below will display more than 1 row of result which I will put a link to every $value['name'] to proceed to the next page. I need to get which link is clicked and I need to get the $value['name'] which corresponds to the link clicked. Can someone help me please.
<div id="searchBox">
<?php
foreach( $row as $value ) // VALUE IS A ROW
{?>
<?php echo " Name: ";
?> <a href='<?php echo base_url()."main/moreinfo" ?>'><?php echo $value['name']; ? ></a>
<?php
echo '<p>';
echo " Type: ";
echo $value['type'];
echo '<p>';
echo "________________________________________________________________________";
echo '<p>';
}
?>
</div>
You achieve this adding an id $value['id'] to your <a href>. Then you are able to query more info in your controller, after the link was clicked:
<div id="searchBox">
<?php
foreach( $row as $value ) {
$url=base_url( "main/moreinfo/".$value['id'] );
echo 'Name: ';
echo '<a href='.$url.'>'.$value['name'].'</a>';
echo '<p>';
echo ' Type: ';
echo $value['type'];
echo '<p>';
echo '____________________________________________________________';
echo '<p>';
}
?>
</div>

Resources