Foros del Web » Programando para Internet » PHP »

Cambiar color texto

Estas en el tema de Cambiar color texto en el foro de PHP en Foros del Web. Hola, tengo una base de datos con los siguientes campos id idn nombre Quiero que me muestre todos los registros, y a los que tenga ...
  #1 (permalink)  
Antiguo 15/02/2010, 15:12
 
Fecha de Ingreso: febrero-2008
Mensajes: 43
Antigüedad: 16 años, 1 mes
Puntos: 1
Cambiar color texto

Hola, tengo una base de datos con los siguientes campos

id
idn
nombre

Quiero que me muestre todos los registros, y a los que tenga idn > 0 los ponga en color rojo, tengo esto que he realizado con dreamweaver

Código PHP:
<?php require_once('Connections/catrautos.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

mysql_select_db($database_catrautos$catrautos);
$query_Recordset1 "SELECT * FROM club_socios";
$Recordset1 mysql_query($query_Recordset1$catrautos) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?>
<!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=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<?php do { ?>
  <p ><?php echo $row_Recordset1['idx']; ?> - 
    <?php echo $row_Recordset1['idn']; ?> - 
    <?php echo $row_Recordset1['nombre']; ?>
      </p>
  <?php } while ($row_Recordset1 mysql_fetch_assoc($Recordset1)); ?></body>
</html>
<?php
mysql_free_result
($Recordset1);
?>
  #2 (permalink)  
Antiguo 15/02/2010, 15:25
Avatar de darkasecas  
Fecha de Ingreso: marzo-2005
Ubicación: SantaCata, NL, Mexico
Mensajes: 1.553
Antigüedad: 19 años
Puntos: 77
Respuesta: Cambiar color texto

puedes colocar los datos dentro de etiquetas <span>, definir una clase CSS para ponerle el color que quieras, y dentro del ciclo verificar la condicion que quieres, si es asi, aplicas la clase al span.
  #3 (permalink)  
Antiguo 15/02/2010, 15:26
 
Fecha de Ingreso: noviembre-2004
Ubicación: NULL
Mensajes: 652
Antigüedad: 19 años, 4 meses
Puntos: 6
Respuesta: Cambiar color texto

pon asi
Código PHP:
    <font color=#ff0000><?php echo $row_Recordset1['idn']; ?></font>

Aqui el codigo
Código PHP:

<?php require_once('Connections/catrautos.php'); ?> 
<?php 
if (!function_exists("GetSQLValueString")) { 
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue "")  

  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

  switch (
$theType) { 
    case 
"text"
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL"
      break;     
    case 
"long"
    case 
"int"
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL"
      break; 
    case 
"double"
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL"
      break; 
    case 
"date"
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL"
      break; 
    case 
"defined"
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue
      break; 
  } 
  return 
$theValue



mysql_select_db($database_catrautos$catrautos); 
$query_Recordset1 "SELECT * FROM club_socios"
$Recordset1 mysql_query($query_Recordset1$catrautos) or die(mysql_error()); 
$row_Recordset1 mysql_fetch_assoc($Recordset1); 
$totalRows_Recordset1 mysql_num_rows($Recordset1); 
?> 
<!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=iso-8859-1" /> 
<title>Documento sin t&iacute;tulo</title> 
</head> 

<body> 
<?php do { ?> 
  <p ><?php echo $row_Recordset1['idx']; ?> -  
    <font color=#ff0000><?php echo $row_Recordset1['idn']; ?></font> -  
    <?php echo $row_Recordset1['nombre']; ?> 
  </p> 
  <?php } while ($row_Recordset1 mysql_fetch_assoc($Recordset1)); ?></body> 
</html> 
<?php 
mysql_free_result
($Recordset1); 
?>
  #4 (permalink)  
Antiguo 15/02/2010, 15:26
Avatar de xcoltx  
Fecha de Ingreso: diciembre-2008
Mensajes: 65
Antigüedad: 15 años, 3 meses
Puntos: 0
Respuesta: Cambiar color texto

hola que tal.. mira reemplaza esta linea tuya de php


Código PHP:
<?php echo $row_Recordset1['idn']; ?>

por esta :


Código PHP:
<?php 
$idn
=$row_Recordset1['idn'];
if(
$idn 0) echo "<span style='color:#FF0000;'>$idn</span>";
else echo 
$idn;
?>

Etiquetas: color
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:20.