PHP code not executing when javascript comes between -
here situation... 2 results created in php page.. results echoed json_encode
. results showing perfectly. when insert javascript code within 2 php code blocks, 1 result shown while other not.. have no idea why happening.. code
$action = isset($_get['action']); if($action == "get_requests"){ include("../connect.php"); $sql_song_req = "select count(*) `song_requests`"; $sql_select_song = "select * `song_requests` order id asc"; $sql_count = $rad->prepare($sql_song_req); $sql_count->execute(); $count = $sql_count->fetchcolumn(); $select_song_prep = $rad->prepare($sql_select_song); $select_song_prep->execute(); while($row = $select_song_prep->fetch(pdo::fetch_assoc)){ $id = $row['id']; $name = $row['name']; $song = $row['songname']; $dedicatedto = $row['dedicatedto']; ?> <script> function delete_req(id){ alert("hello"); } </script> <?php $data .= ' <tr cellpadding="5" cellspacing="6" align="center" width="60%"> <td>'.$id.'</td> <td>'.$name.'</td> <td>'.$song.'</td> <td>'.$dedicatedto.'</td> <td><a href="javascript:;" onclick="delete_req('.$id.');" style="background:black; color:white; padding:8px;">delete</a></td> </tr>'; } $display = ' <table "cellspacing="4" align="center"> <tr> <th>id</th> <th>name</th> <th>song</th> <th>dedicated to</th> <th>delete</th> '.$data.' </tr> </table>'; $response = array(); $response['data_from_db'] = $display; $response['count'] = $count; echo json_encode($response); }
here response['count']
showing on php page not $response['data_from_db']
. , when delete javascript code both of them showing.. needed.
i should mention using nginx , php5-fpm
you have brace mismatch.
add brace }
after $dedicatedto = $row['dedicatedto'];
while
loop wasn't closed.
$action = isset($_get['action']); if($action == "get_requests"){ include("../connect.php"); $sql_song_req = "select count(*) `song_requests`"; $sql_select_song = "select * `song_requests` order id asc"; $sql_count = $rad->prepare($sql_song_req); $sql_count->execute(); $count = $sql_count->fetchcolumn(); $select_song_prep = $rad->prepare($sql_select_song); $select_song_prep->execute(); while($row = $select_song_prep->fetch(pdo::fetch_assoc)){ $id = $row['id']; $name = $row['name']; $song = $row['songname']; $dedicatedto = $row['dedicatedto']; } // <- added. brace while loop ?> <script> function delete_req(id){ alert("hello"); } </script> <?php $data .= ' <tr cellpadding="5" cellspacing="6" align="center" width="60%"> <td>'.$id.'</td> <td>'.$name.'</td> <td>'.$song.'</td> <td>'.$dedicatedto.'</td> <td><a href="javascript:;" onclick="delete_req('.$id.');" style="background:black; color:white; padding:8px;">delete</a></td> </tr>'; $display = ' <table "cellspacing="4" align="center"> <tr> <th>id</th> <th>name</th> <th>song</th> <th>dedicated to</th> <th>delete</th> '.$data.' </tr> </table>'; $response = array(); $response['data_from_db'] = $display; $response['count'] = $count; echo json_encode($response); }
Comments
Post a Comment