Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/11/2012, 15:19
karma274
 
Fecha de Ingreso: septiembre-2012
Ubicación: Norte de Santander
Mensajes: 127
Antigüedad: 11 años, 7 meses
Puntos: 1
Pregunta Problemas con array error illegal string offset...

Buenas, lo que pasa es que quiero imprimir un array que obtenido desde un script de busqueda pero cuando hago el foreach me imprime un error que me dice illegal string offset, en lo que me gustaria que me ayudaran es si hay otra forma de inprimir este array. Les dejo los scripts para que sea mas facil de comprender...

script prueba.php que llama a la funcion buscar
Código PHP:
Ver original
  1. <?php
  2. include("../funciones/buscar.php");
  3.     if(isset($_POST['submit'])) {
  4.     $barrio = $_POST['barrio'];
  5.     }
  6. ?>
  7. <html>
  8. <head>
  9. <title></title>
  10. </head>
  11. <body>
  12. <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  13. <label>CONSULTA:<input type="text" name="barrio" value="" /><br /></label>
  14. <input type="submit" name="submit" value="Comprobar Barrio" /><br /><br />
  15. <?php
  16. $res = buscar($barrio);
  17. if($res != null){
  18. ?>
  19. <label>BARRIO:&nbsp;&nbsp;<input type="text" name="barr" value="<?php echo $res['barrio'];?>" /></label>&nbsp;&nbsp;&nbsp;
  20. <label>CIUDAD:&nbsp;&nbsp;<input type="text" name="ciudad" value="<?php echo $res['ciudad'];?>" /></label>&nbsp;&nbsp;&nbsp;
  21. <label>COMUNA:&nbsp;&nbsp;<input type="text" name="comuna" value="<?php echo $res['comuna'];?>" /></label><br />
  22. <?php
  23. }else{
  24. echo '<span style="color:red">ERROR DE CONSULTA</span>';
  25. }
  26. ?>
  27. </form>
  28. </body>
  29. </html>

script buscar.php
Código PHP:
Ver original
  1. <?php
  2. include("../conexiones/conexion.php");
  3. function buscar($dato){
  4. $barrio=$dato;
  5. $sql = mysql_query("SELECT * FROM barrios WHERE barrio LIKE '%".$barrio."%'");
  6. if(mysql_num_rows($sql)>0){
  7.         $res=mysql_fetch_assoc($sql);
  8.         return ($res);
  9.     }
  10. }
  11. ?>