Ver Mensaje Individual
  #2 (permalink)  
Antiguo 18/05/2009, 14:14
Avatar de the_web_saint
the_web_saint
 
Fecha de Ingreso: mayo-2008
Ubicación: localhost/tierra/america/panama
Mensajes: 1.229
Antigüedad: 15 años, 11 meses
Puntos: 43
Respuesta: creo que esta bien pero no corre...

Código php:
Ver original
  1. <html>
  2. <Head>
  3. <style type="text/css">
  4. a.p:link { color: #0066FF; text-decoration: none; }
  5. a.p:visited { color: #0066FF; text-decoration: none; }
  6. a.p:active { color: #0066FF; text-decoration: none; }
  7. a.p:hover { color: #0066FF; text-decoration: underline; }
  8. a.ord:link { color: #000000; text-decoration: none; }
  9. a.ord:visited { color: #000000; text-decoration: none; }
  10. a.ord:active { color: #000000; text-decoration: none; }
  11. a.ord:hover { color: #000000; text-decoration: underline; }
  12. </style>
  13. </Head>
  14. <body>
  15. <div align="center"><strong><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">Paginación
  16. de Resultados de la consulta SQL (sobre DB Fundabol)<br><br><p></p> </font></strong> </div>
  17. <hr noshade style="color:CC6666;height:1px"></Hr>
  18.  
  19. <p> CONSULTA DE ALUMNOS
  20. <hr noshade style = "color:CC6666;height:1px" ></hr>
  21.  
  22. <FORM METHOD="post"><br>
  23. Seleccione Grupo: <br>
  24. <select name="Curso"><br>
  25. <option value="1">Php</option>
  26. <option value="2">Visual</option>
  27. <option value="3">Excel</option>
  28. <option value="4">Winword</option>
  29. </select>
  30. <br><input type="text" name="codigo" value=""/><br>
  31. <br>
  32. <input type="radio" name="radio1" value="Por_codigo">Codigo <br>
  33. <input type="radio" name="radio2" value="all">Todos <br>
  34. <input type="submit" name="operar">
  35.  
  36. </form>
  37.  
  38.  
  39. <?php
  40. $conexion=mysql_connect("localhost","root","") or die("Problemas en la conexion");
  41. mysql_select_db("fundabol",$conexion) or die("Problemas en la selección de la base de datos");
  42.  
  43. if (isset($_POST['radio1']) && $_POST['radio1']!=""){
  44.  
  45. switch($_POST['radio1']){
  46.  
  47. case 'Por_codigo':
  48.  
  49. $codigo=$_POST['codigo'];
  50. $result = mysql_query("____") or die("Error SQL excel,php,visual,winword: ".mysql_error());
  51. $result_cantidad = mysql_num_rows($result);
  52.  
  53. break;
  54.  
  55. case 'all':
  56.  
  57. if($_POST['Curso']){
  58.  
  59. switch($_POST['Curso']){
  60.  
  61. case 1: $tabla = 'php'; break;
  62. case 2: $tabla = 'visual'; break;
  63. case 3: $tabla = 'excel'; break;
  64. case 4: $tabla = 'winword'; break;
  65.  
  66. }
  67. if($_POST['Curso']==case 3){
  68. $sql = "SELECT codigo,nombre,Email,pago1,pago2,pago3,pago4 FROM $tabla";
  69. $result = mysql_query($sql, $conexion)or die("Error trayendo la informacion de la base de datos");
  70. $result_cantidad = mysql_num_rows($result);
  71.  
  72. }}
  73.  
  74. break;
  75. }
  76.  
  77.  
  78. //si la cantidad del resultado es cero
  79.  
  80. if($result_cantidad == 0){
  81.  
  82. echo "La base de datos está vacia";
  83.  
  84. }else{
  85.  
  86. //cosa importante, separar el codigo html del codigo php, permite una mejor vision
  87. // y detectar problemas mucho mas facil.
  88. ?>
  89.  
  90. <table border='1'>
  91. <tr>
  92. <th>Codigo</th>
  93. <th>Nombre</th>
  94. <th>Email</th>
  95. <th>Pago 1</th>
  96. <th>Pago 2</th>
  97. <th>Pago 3</th>
  98. <th>Pago 4</th>
  99.  
  100. </tr>
  101. <tr>
  102.  
  103. <? while($row = mysql_fetch_array($result)){?>
  104.  
  105. <td><? echo $row['codigo'] ?></td>
  106. <td><? echo $row['nombre'] ?></td>
  107. <td><? echo $row['Email'] ?></td>
  108. <td><? echo $row['pago1'] ?></td>
  109. <td><? echo $row['pago2'] ?></td>
  110. <td><? echo $row['pago3'] ?></td>
  111. <td><? echo $row['pago4'] ?></td>
  112.  
  113. <?} ?>
  114. </tr>
  115. </table>
  116. <?}
  117.  
  118. mysql_close($conexion);
  119.  
  120. }
  121.  
  122. </body>
  123. </html>

Bueno te dejo esto, epro tengo varias dudas:

1. Como se llaman los campos?, se escribe con mayuscula o minuscula?
2. Quieres seleccionar campos de varias tablas?
3. Cuando dices * en la primera consulta, todas estas tablas tienen la misma cantidad, en el mismo orden y exactamente escritos de la misma forma de campos?

Saludos, espero tu respuesta
__________________
..::The Saint::..
El pesimista se queja del viento; el optimista espera que cambie; el realista ajusta las velas.