3

Let me tell you in brief what I am doing ..

I am doing pagination using a library where the pagination is just showing the 3 <li> at a time. and What I am doing on that <li> is I have a php array with me and I am creating a table in that <li> that each <li> will have table with 8 rows so the 8 elements of the array has been displayed with the help of php code.

This is the code.

    <?php
        $data = array();
        $no_of_Items = 8;
        $k = 1;

        for ($i = 1; $i <= 100; $i++) {
            $data[$i - 1] = "striker" . $i;
        }
        ?>
    <select id="view" >
        <option value="1">Midfielder</option>
        <option value="2">Striker</option>
        <option value="3">Defender</option>
        <option value="4">Goal-Keeper</option>
    </select>

<div id="pagination">
     <ul id="demo">
         <?php
             $lis = ceil(count($data) / $no_of_Items);

              for ($i = 1; $i <= $lis; $i++) {
          ?>
          <li>
              <table  id="tbl-li">
                  <?php
                      for ($j = 1; $j <= $no_of_Items; $j++) {
                           if (empty($data[$k - 1])) {
                               break;
                            }
                  ?>
                  <tr style="padding: 0; margin: 0;">
                       <td><?php echo $data[$k - 1]; ?></td>
                       <td>CHE</td>
                       <td>11.5</td>
                       <td>142</td>
                 </tr ><?php $k++; } ?>
             </table>
           </li>
           <?php } ?>
      </ul>
    </div>

so what I am doing now is just passing the one array to the pagination div but i have 4 arrays for defender as well as for all the item contains in the select tag .

So my final question is how to provide to my code the php when I select the appropriate option from the select?

I have tried this but I know this will not going to work so any suggestion or any other way?

My js

    var selectval;
                    $('#view').on('change', function () {
                        selectval = $(this).val();
                    });

                    if (selectval === 1)
                    {
<?php
for ($i = 1; $i <= 100; $i++) {
    $data[$i - 1] = "midfielder" . $i;
}
?>
                    }
                    else if (selectval === 2) {
<?php
for ($i = 1; $i <= 100; $i++) {
    $data[$i - 1] = "striker" . $i;
}
?>
                    }
                    else if (selectval === 3) {
<?php
for ($i = 1; $i <= 100; $i++) {
    $data[$i - 1] = "defender" . $i;
}
?>
                    }
                    else if (selectval === 3) {
<?php
for ($i = 1; $i <= 100; $i++) {
    $data[$i - 1] = "goalkeeper" . $i;
}
?>
                    }
6
  • use js to generate the table on change. php will not help i think. Commented May 9, 2015 at 4:39
  • I am trying but there are some problem with js bcoz i really dont know js well Commented May 9, 2015 at 5:02
  • then learn js first. Commented May 9, 2015 at 5:02
  • yeah.. is it possible that the php code I have generated I can do same thing with javascript....like can I do combination of html and js just hunit that is it possible or not? Commented May 9, 2015 at 5:04
  • on client side php will not work. Commented May 9, 2015 at 5:07

1 Answer 1

2

Try This it will work..

$('#view').select(function(){   
                    var valselect = $('#view').val();
                        console.log(valselect);
                        var data = [];
                        var i, j, k = 1;
                        var code = '';
                        var no_item = 8;


                        if (valselect === "1")
                        {
                            for (i = 1; i <= 50; i++) {
                                data[i - 1] = "Midfielder" + i;

                            }
                            console.log(data);
                        }
                        else if (valselect === "2")
                        {

                            for (i = 1; i <= 50; i++) {
                                data[i - 1] = "Striker" + i;
                            }
                            console.log(data);
                        }
                        else if (valselect === "3")
                        {
                            for (i = 1; i <= 50; i++) {
                                data[i - 1] = "Defender" + i;

                            }
                            console.log(data);
                        }
                        else if (valselect === "4") {
                            for (i = 1; i <= 50; i++) {
                                data[i - 1] = "Goal-keeper" + i;

                            }
                            console.log(data);
                        }



                        var lis = Math.ceil(data.length / no_item);


                        console.log(lis);

                        for (i = 1; i <= lis; i++)
                        {
                        console.log("outerloop="+i);
                            code += "<li><table id='tbl-li'>";

                            for (j = 1; j <= no_item; j++) {
                            console.log("j=" + j);

                                if (data[k - 1])
                                {
//                                console.log("k=" + k);
                                    code += "<tr><td><img src='/img/info.png'>" + data[k - 1] + "</td><td>CHE</td><td>11.5</td><td>142</td></tr>";
                                    k++;
                                }
                                else {
//                                console.log("val k=="+k);
                                    break;
                                }
                            }
                            code += "</table></li>";
                        }

//                    console.log(code);

//                        $('#demo').append();
                        $('#demo').html(code);
                    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.