Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/06/2010, 13:04
benjaminvera
 
Fecha de Ingreso: junio-2008
Mensajes: 101
Antigüedad: 16 años, 7 meses
Puntos: 0
Reemplazar NULL con str_replace.... Cómo reemplazarlo?????

De casualidad alguien puede decirme por qué no me está reemplazando el valor default NULL en esta sentencia de PHP....

str_replace(NULL,"Sin valor",$row['valor'])

Código PHP:
Ver original
  1. if (!mysql_connect($db_host, $db_user, $db_pwd))
  2.     die("Can't connect to database");
  3.  
  4. if (!mysql_select_db($database))
  5.     die("Can't select database");
  6.  
  7. // sending query
  8. $result = mysql_query("select {$table}.nomb_gpo,{$table}.nomb_ind,valor from {$table} join indicador on {$table}.nomb_ind=indicador.nomb_ind
  9. where nomb_pla='$_REQUEST[plan_inst]' and nomb_cen='$_REQUEST[cen_trabajo]'  and mes='{$mth}' and ano='{$yr}' order by id_ind asc limit 0,3;"
  10. ,$conexion) or die("Problemas en el select result: ".mysql_error());
  11.  
  12. echo "<table id=\"demo4_table\" cellpadding=\"2\" cellspacing=\"1\" border=\"2\"  width=\"453\" align=left >";
  13.  
  14. // printing table rows
  15. echo "<tr><td  rowspan='1' colspan='3' align='center' bgcolor='58ACFA'><b>Instalaciones y Equipos</b></td></tr>\n";
  16.  
  17. while ($row = mysql_fetch_array($result))
  18. {
  19. echo "<TR>";
  20.         echo "<TD>".$row['nomb_ind']."</TD>";
  21.         echo "<TD width=\"83\" align=center>".str_replace(NULL,"Sin valor",$row['valor'])."</TD>";
  22.     echo "</tr>\n";
  23. }

El pequeño gran detalle es que NO me está reemplazando el Valor NULL por "Sin Valor"....

Para verificar que la parte de MySQL sí está trabajando bien pongo lo siguiente:

Código MySQL:
Ver original
  1. mysql> select valor from clau where mes='Nov' and ano=2009 and nomb_pla='Planta 1';
  2. +-------+
  3. | valor |
  4. +-------+
  5. |  NULL |
  6. |  NULL |
  7. |  NULL |
  8. |  NULL |
  9. |  NULL |
  10. |  NULL |
  11. |  NULL |
  12. |  NULL |
  13. |  NULL |
  14. |  NULL |
  15. |  NULL |
  16. |  NULL |
  17. |  NULL |
  18. +-------+
  19. 13 rows in set (0.01 sec)