0

I have a .php file wherein, a popup opens which has to display some data from the db when a button is clicked. There are 30 different buttons and all display different data. But the code I have written does not seem to be working. This is my code:

<?php
    echo "<script>function getDataFunction(clicked_id){
        $id=clicked_id;
    }</script>";

    session_start();
    $phone=$_SESSION['phone'];
    $query= "(SELECT * FROM timetable WHERE ID == '$id')";
    $result = mysqli_query($conn, "SELECT * FROM timetable WHERE ID == '$id'");
    $row = $result->fetch_assoc();
    $timefrom=$row['timefrom'];
    $timeto=$row['timeto'];
    $status=$row['stat'];
    $comment=$row['comm'];

?>
  • What is mean by this ` $id=clicked_id;`? – Nawin Mar 22 '18 at 09:22
  • First: What Nawin writed. Second: What does your browser's console says? – Flocke Mar 22 '18 at 09:24
  • See the difference between server side and client side script. See https://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript – B. Desai Mar 22 '18 at 09:25
  • You cannot output anything before session_start(); : it'll cause a header sent error. https://stackoverflow.com/questions/8812754/cannot-send-session-cache-limiter-headers-already-sent – Karlo Kokkak Mar 22 '18 at 09:26
  • The query is running before your js can populate the $id variable from the user click. You should use ajax call inside your js function to run your query, – Joseph_J Mar 22 '18 at 09:26
  • i would suggest that you don't and find a better way to structure your code. – Juakali92 Mar 22 '18 at 09:27
  • 1
    Maybe try to use Ajax : you send your the id in your php file, you make your request and return the result, then you display the result in your popup in the front – Mickaël Leger Mar 22 '18 at 09:28
  • Can you use jQuery? – Mickaël Leger Mar 22 '18 at 09:32

1 Answers1

-1

You can write javascript code inside php tag like this.

<?php echo "<script> </script>"; ?>