pGibson 0 Denunciar post Postado Julho 22, 2011 Bem, tava começando a fazer programas em PHP hoje e, como um auto-desafio, eu tentei fazer um botão que printasse na tela o número de registros e dados da tabela MySQL. Mas não printa nada... <?php include( "/config/sql_connect.php" ); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>TERRA San Fierro Chapter ACP</title> <style type="text/css"> body,td,th { font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; font-size: 14px; color: #F90; } body { background-color: #FFF; margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } </style> <script type="text/javascript"> function displayTable() { document.write("<?php //////////////////////////////////////////////////////////////// $result = mysqli_query( $conexao, "SELECT * FROM playerinfo" ); $linhas = mysqli_num_rows( $result ); //////////////////////////////////////////////////////////////// echo( "<p>Número de registros: $linhas</p>\n\n" ); echo "<table width=\"600\" border=\"1\" align=\"left\" height=\"60\">"; for( $i = 0; $i < $linhas; $i++ ) { echo "<tr>"; $row = mysqli_fetch_row($result); $admin = ( ( $row[5] ) > 0 ) ? ( "sim" ) : ( "não" ); echo "<td>CID: $row[0]</td> <td>Nome: $row[1]</td> <td>Nível: $row[3]</td> <td>Respeito: $row[4]</td><td>Admin: $admin</td>" ; echo "</tr>"; } echo "</table>"; mysqli_close( $conexao ); ?>"); } </script> </head> <body> <button type="button" onclick="displayTable()">Mostrar Tabela</button> <p id="out">Shit comes out'ere bro.</p> </body> </html> O problema é bem aqui. document.write("<?php Eu não sei se isso é possivel ;s Compartilhar este post Link para o post Compartilhar em outros sites
Rafael Rosario 4 Denunciar post Postado Julho 22, 2011 Da um mysql_error() na query pra ver se retorna algum tipo de erro. Compartilhar este post Link para o post Compartilhar em outros sites
pGibson 0 Denunciar post Postado Julho 22, 2011 Bem, o problema não é no código PHP, pois eu já executei antes de colocar como função em jS. (Não retornou nenhum erro) A única coisa que eu duvido é colocar Tábelas derivadas de códigos PHP em funções de jS como document.write ou innerHTML :S function displayTable() { document.write("<?php //////////////////////////////////////////////////////////////// $result = mysqli_query( $conexao, "SELECT * FROM playerinfo" ); $linhas = mysqli_num_rows( $result ); //////////////////////////////////////////////////////////////// echo( "<p>Número de registros: $linhas</p>\n\n" ); echo "<table width=\"600\" border=\"1\" align=\"left\" height=\"60\">"; for( $i = 0; $i < $linhas; $i++ ) { echo "<tr>"; $row = mysqli_fetch_row($result); $admin = ( ( $row[5] ) > 0 ) ? ( "sim" ) : ( "não" ); echo "<td>CID: $row[0]</td> <td>Nome: $row[1]</td> <td>Nível: $row[3]</td> <td>Respeito: $row[4]</td><td>Admin: $admin</td>" ; echo "</tr>"; } echo "</table>"; mysqli_close( $conexao ); ?>"); } Compartilhar este post Link para o post Compartilhar em outros sites