Buenos Dias!
Llevo un ratillo consultando un ejemplo y ya me estan empezando a entrar sudores xq no entiendo que es lo que pasa. El codigo es el siguiente:
Código PHP:
<?php
echo '
<!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>
<title>My Books</title>
<style type="text/css" title="currentStyle">
@import "media/css/demo_page.css";
@import "media/css/demo_table.css";
@import "media/css/themes/base/jquery-ui.css";
@import "media/css/themes/smoothness/jquery-ui-1.7.2.custom.css";
</style>
<script src="media/js/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="media/js/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="media/js/jquery.jeditable.js" type="text/javascript"></script>
<script src="media/js/jquery-ui.js" type="text/javascript"></script>
<script src="media/js/jquery.validate.js" type="text/javascript"></script>
<script src="media/js/jquery.dataTables.editable.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$(\'#example\').dataTable( {
"bPaginate": true,
} );
} );
</script>
</head>
<body>
<p>Books</p>
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
';
// Database access data
$database="databasephp";
$host="localhost";
$user="root";
$password="pass";
$table="books";
mysql_connect($host,$user,$password);
mysql_select_db($database) or die( "Unable to select database");
echo '
<thead>
<tr>
';
$query = "show columns from $table";
$result = mysql_query($query);
while ( $row = mysql_fetch_assoc($result) )
{
$fieldname = $row['Field'];
if ( $fieldname == 'id' ) continue;
echo "<th>$fieldname</th>";
}
echo '
</tr>
</thead>
<tbody>
';
$query = "select * from $table";
$result = mysql_query($query);
while ( $row = mysql_fetch_assoc($result) )
{
unset($row['id']);
echo "<tr>";
foreach ($row as $key => $value)
{
echo "<td>$value</td>";
}
echo "</tr>";
}
echo '
</tbody>
</table>
</body>
</html>
';
?>
Como se puede ver en el ejemplo, utiliza un script php para toda la pagina, a mi esta forma no me termina de convencer por lo que solo incluyo <?php ?> en aquellas partes donde es necesario.
Bien, si saco toda la cabecera (<head>) del script php, y elimino ese echo ' ', no se xq razon el codigo deja de funcionar, no me carga bien ni los estilos css ni las librerias javascript.
Código 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>
<title>My Books</title>
<style type="text/css" title="currentStyle">
@import "media/css/demo_page.css";
@import "media/css/demo_table.css";
@import "media/css/themes/base/jquery-ui.css";
@import "media/css/themes/smoothness/jquery-ui-1.7.2.custom.css";
</style>
<script src="media/js/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="media/js/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="media/js/jquery.jeditable.js" type="text/javascript"></script>
<script src="media/js/jquery-ui.js" type="text/javascript"></script>
<script src="media/js/jquery.validate.js" type="text/javascript"></script>
<script src="media/js/jquery.dataTables.editable.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$(\'#example\').dataTable( {
"bPaginate": true,
} );
} );
</script>
</head>
<body>
<p>Books</p>
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<?php
// Database access data
$database="databasephp";
$host="localhost";
$user="root";
$password="pass";
$table="books";
mysql_connect($host,$user,$password);
mysql_select_db($database) or die( "Unable to select database");
echo '
<thead>
<tr>
';
$query = "show columns from $table";
$result = mysql_query($query);
while ( $row = mysql_fetch_assoc($result) )
{
$fieldname = $row['Field'];
if ( $fieldname == 'id' ) continue;
echo "<th>$fieldname</th>";
}
echo '
</tr>
</thead>
<tbody>
';
$query = "select * from $table";
$result = mysql_query($query);
while ( $row = mysql_fetch_assoc($result) )
{
unset($row['id']);
echo "<tr>";
foreach ($row as $key => $value)
{
echo "<td>$value</td>";
}
echo "</tr>";
}
echo '
</tbody>
</table>
</body>
</html>
';
?>
A que se debe??? en ese trozo de codigo no hay nada de php. Xq tengo q incluirlo en el script para que funcione??