Use href to open a php page from selected row

Use href to open a php page from selected row

neelsfneelsf Posts: 15Questions: 6Answers: 1
edited June 2017 in Free community support

I just love your tables, but have small problem. I need to open another php edit page filtered on the same record as the selected row. I use this in other "inferior "tables to yours, and it works just fine <td><a href="update2.php?u=<?php echo $row['id'] ?>"><span class="glyphicon glyphicon-pencil" aria-hidden="true" </span><b><font size="3" color="red"</font> Edit<b></a></td>

The table i am using now is the "Individual column searching (select inputs) and server-side"
Any advice please? Thx for assisting this novice and keep up good work pls

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Use column.render to insert the url into your table.

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin

    See the manual and columns.render documentation for information on how to render a link into a DataTable from plain unformatted data.

    Allan

  • neelsfneelsf Posts: 15Questions: 6Answers: 1
    edited June 2017

    Perhaps i explained myself wrong. How do i pass a variable in a table, for example the "id" field from the selected row using the POST method, to another php form .(<a href="update2.php?u=<?php echo $row['id'] ?>"). Please be so kind to assist. I use a checkbox to select row.

    To delete a row i use this now and it works. The same checkbox will be used to open the form update2.php using the same record. I need to push this "id" to the php page in URL from the table selected row
    example for delete

    $('#deleteTriger').on("click", function(event){ // triggering delete one by one
                        if( $('.deleteRow:checked').length > 0 ){  // at-least one checkbox checked
                            var ids = [];
                            $('.deleteRow').each(function(){
                                if($(this).is(':checked')) { 
                                    ids.push($(this).val());
                                }
                            });`
    `var ids_string = ids.toString();  // array to string conversion 
                            $.ajax({
                                type: "POST",
                                url: "employee-delete.php",
                                data: {data_ids:ids_string},
                                success: function(result) {
                                    dataTable.draw(); // redrawing datatable
                                },
                                async:false
    $data_ids = $_REQUEST['data_ids'];
    $data_id_array = explode(",", $data_ids); 
    if(!empty($data_id_array)) {
        foreach($data_id_array as $id) {
            $sql = "DELETE FROM users ";
            $sql.=" WHERE id = '".$id."'";
            $query=mysqli_query($conn, $sql) or die("employee-delete.php: delete employees");
        }
    }
    

    In the table php i have $nestedData[] = "<input type='checkbox' class='deleteRow' value='".$row['id']."' /> #".$i ;
    The edit button id="editTriger and should open the update2.php page. I will then use this variable to filter the sql in update2.php
    Thx for assisting pretty please

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin

    To be perfectly honest, I don't actually understand exactly what you are looking for.

    You mention editTriger, but I don't see that anywhere in your code.

    The columns.render option is how you should create a button or a link inside a table's cell to open a new page.

    Allan

  • neelsfneelsf Posts: 15Questions: 6Answers: 1
    edited June 2017 Answer ✓

    Thx. Got it working using this code, after 3 days of struggling, with only 3 lines of code. It's tough, when one is stupid. hehe The row[1] did the trick. Thx

    $(document).ready(function() {
                    var dataTable = $('#employee-grid').DataTable( {
                        "processing": true,
                        "serverSide": true,
                        "columnDefs": [ {
                              "targets": 0,
                              "orderable": false,
                              "searchable": false,
                               "render": function ( data, type, row ) {
                                return '<a href="update2.php?u=' + row[1] +'">' + data + '</a>';
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin

    Good to hear you have it working. Thanks for posting back.

    Allan

This discussion has been closed.