Foros del Web » Programando para Internet » PHP »

ayuda para un primer esbozo

Estas en el tema de ayuda para un primer esbozo en el foro de PHP en Foros del Web. tengo q hacer una funcion en php que tome un valor entero entre 1 y 3 y devuelva de la paleta de colores el color ...
  #1 (permalink)  
Antiguo 17/04/2005, 05:21
 
Fecha de Ingreso: abril-2005
Mensajes: 14
Antigüedad: 19 años
Puntos: 0
ayuda para hacer codigo

tengo q hacer una funcion en php que tome un valor entero entre 1 y 3
y devuelva de la paleta de colores el color verde, amarillo o rojo.
si es 0 mostrara el blanco.

gracias
  #2 (permalink)  
Antiguo 17/04/2005, 05:38
Avatar de jam1138
/** @package Moderador */
 
Fecha de Ingreso: julio-2004
Ubicación: sèveR led onieR lE
Mensajes: 9.368
Antigüedad: 19 años, 8 meses
Puntos: 102
¿qué haz intentado?
Código PHP:
<?
function color($valor) {
    if(!
is_int($valor)) return false;
    else if(
$valor<=3) {
        switch(
$valor) {
            case 
0: return "WHITE"; break;
            case 
1: return "GREEN"; break;
            case 
2: return "YELLOW"; break;
            case 
3: return "RED"; break;
        }
    }
}
echo 
"<table>";
for (
$i=-1$i<=4$i++) {
    echo 
"<tr><td>Valor: $i</td><td>Valor devuelto: ".color($i)."</td><td width=\"50\" bgcolor=\"".color($i)."\"></td></tr>"
}
echo 
"</table>";
?>
__________________
٩(͡๏̯͡๏)۶
» Cómo hacer preguntas de manera inteligente «

"100 años después, la revolución no es con armas, es intelectual y digital"
  #3 (permalink)  
Antiguo 04/05/2005, 02:12
 
Fecha de Ingreso: abril-2005
Mensajes: 14
Antigüedad: 19 años
Puntos: 0
funciones y argumentos

Hola a todo!

Estoy haciendo funciones que me han ido mandado pero me he quedado atascado aqui,
a ver si me podriais ayudar a resolverlo.

Para empezar me pidieron lo siguiente:

- Haz una funcion que reciba un entero entre 1 y 3
y muestre en la tabla el color
verde, amarillo ou rojo.
Si es 0 mostrata blanco.
(lo que permite hacer un codigo de color para las alarmas)

Codigo empleado:

<?
function color($valor) {
if(!is_int($valor)) return false;
else if($valor<=3) {
switch($valor) {
case 0: return "WHITE"; break;
case 1: return "GREEN"; break;
case 2: return "YELLOW"; break;
case 3: return "RED"; break;
}
}
}
echo "<table>";
for ($i=-1; $i<=4; $i++) {
echo "<tr><td>Valor: $i</td><td>Valor devuelto: ".color($i)."</td><td width=\"50\" bgcolor=\"".color($i)."\"></td></tr>";
}
echo "</table>";
?>

Pues bien, a partir de aqui me piden incluir las siguientes funciones para completarlo:

- alarmes_cn -> que devuelve el valor (0,1,2,3)

si un cn se ha pasado -> rojo
si le queda el 10% -> amarillo
si no le queda el 10% -> verde
si error -> blanco


- alarmes_visite ->
si una visita se ha pasado -> rojo
si le queda el 10% -> amarillo
sino verde



- alarme_equipement -> idem


Para esto tengo la siguiente bd, ya fijada:
(para el formato de los datos)

-- --------------------------------------------------------

--

-- Structure de la table `avion`
--

CREATE TABLE `avion` (
`Immatriculation` varchar(6) NOT NULL default '',
`Potentiel` int(7) NOT NULL default '0',
`IdType` int(5) NOT NULL default '0',
PRIMARY KEY (`Immatriculation`)
) ;

-- --------------------------------------------------------

--
-- Structure de la table `cdv`
--

CREATE TABLE `cdv` (
`DateV` date NOT NULL default '0000-00-00',
`DureeV` int(6) NOT NULL default '0',
`Cycles` int(2) NOT NULL default '0',
`Descriptif` varchar(100) NOT NULL default '',
`Immatriculation` varchar(6) NOT NULL default '',
PRIMARY KEY (`DateV`,`Immatriculation`)
);

-- --------------------------------------------------------

--
-- Structure de la table `cn`
--

CREATE TABLE `cn` (
`IdCn` int(5) NOT NULL default '0',
`Pays` varchar(15) NOT NULL default '',
`NSerie` varchar(30) NOT NULL default '',
`Texte` varchar(200) NOT NULL default '',
`Date` date NOT NULL default '0000-00-00',
`Revision` int(3) NOT NULL default '0',
`Type_Cn` varchar(15) NOT NULL default '',
PRIMARY KEY (`IdCn`)
) ;

-- --------------------------------------------------------

--
-- Structure de la table `concerne`
--

CREATE TABLE `concerne` (
`Date_App` date NOT NULL default '0000-00-00',
`Cycle_App` int(6) NOT NULL default '0',
`Heure_App` int(6) NOT NULL default '0',
`Mois_Inter` int(6) NOT NULL default '0',
`IdCn` int(5) NOT NULL default '0',
`Immatriculation` varchar(6) NOT NULL default ''
) ;

-- --------------------------------------------------------

--
-- Structure de la table `equipement`
--

CREATE TABLE `equipement` (
`IdEq` int(5) NOT NULL default '0',
`Desi` varchar(30) NOT NULL default '',
`Marque` varchar(30) NOT NULL default '',
`Type` varchar(10) NOT NULL default '',
`P/N` varchar(20) NOT NULL default '',
`S/N` varchar(20) NOT NULL default '',
`Pot_Cal` int(6) NOT NULL default '0',
`Pot_Duree` int(6) NOT NULL default '0',
`Immatriculation` varchar(6) NOT NULL default '',
PRIMARY KEY (`IdEq`)
) ;

-- --------------------------------------------------------

--
-- Structure de la table `passe`
--

CREATE TABLE `passe` (
`Date` date NOT NULL default '0000-00-00',
`Potentiel` int(6) NOT NULL default '0',
`Atelier` varchar(30) NOT NULL default '',
`Immatriculation` varchar(6) NOT NULL default '',
`IdTypeV` int(5) NOT NULL default '0'
) ;

-- --------------------------------------------------------

--
-- Structure de la table `possede`
--

CREATE TABLE `possede` (
`IdProp` int(5) NOT NULL default '0',
`Immatriculation` varchar(6) NOT NULL default ''
) ;

-- --------------------------------------------------------

--
-- Structure de la table `progentr`
--

CREATE TABLE `progentr` (
`IdTypeA` int(5) NOT NULL default '0',
`IdTypeV` int(5) NOT NULL default '0'
) ;

-- --------------------------------------------------------

--
-- Structure de la table `proprietaire`
--

CREATE TABLE `proprietaire` (
`IdProp` int(5) NOT NULL default '0',
`Nom` varchar(30) NOT NULL default '',
`Prenom` varchar(30) NOT NULL default '',
`AdrP` varchar(50) NOT NULL default '',
`AdrE` varchar(30) NOT NULL default '',
`Telephone` varchar(15) NOT NULL default '',
PRIMARY KEY (`IdProp`)
) ;

-- --------------------------------------------------------

--
-- Structure de la table `revise`
--

CREATE TABLE `revise` (
`IdEq` int(5) NOT NULL default '0',
`IdTypeV` int(5) NOT NULL default '0'
);

-- --------------------------------------------------------

--
-- Structure de la table `typeavion`
--

CREATE TABLE `typeavion` (
`IdTypeA` int(5) NOT NULL default '0',
`Marque` varchar(30) NOT NULL default '',
`Modele` varchar(30) NOT NULL default '',
PRIMARY KEY (`IdTypeA`)
) ;

-- --------------------------------------------------------

--
-- Structure de la table `typevisite`
--

CREATE TABLE `typevisite` (
`IdTypeV` int(5) NOT NULL default '0',
`Cyclicite_pot` int(10) NOT NULL default '0',
`Nom` varchar(10) NOT NULL default '',
`Description` varchar(100) NOT NULL default '',
PRIMARY KEY (`IdTypeV`)
) ;

-- --------------------------------------------------------

--
-- Structure de la table `user`
--

CREATE TABLE `user` (
`login` varchar(10) NOT NULL default '',
`password` varchar(10) NOT NULL default '',
`IdProp` int(5) NOT NULL default '0'
);


Y me dan estos argumentos:


- pot_cellule (en minutes)


- limite_potentiel(en minutes)


- potentiel_calendaire (en mois)


- date_application(date)


Para que sobre estos datos, indique el codigo del color de la seccion
(teniendo en cuenta el tope del calendario y de la potencia)



Para que lo entiendais, mas o menos, se trata de un programa de gestion de un taller
de aeronautica. En el hay un listado de todos sus aviones, y en una tabla
se indica todas las caracteristicas de estas. En ella se indica con colores
en su respectiva celdas en rojo, amarillo, verde o blanco el estado
en q se encuentra cada avion, para que el taller sepa cuando van a venir, y cuales
estan en el aire o en taller.


He intentado ver como poder hacerlo, pero no encuentro una forma, pq desconozco
aun muchas cosas del lenguage y como usar sus argumentos. Y como poder realizar las
funciones q aun tengo q añadir.

Por eso si me podrias ayudar a hacerlo, indicandomelo correctamente, me ayudarias a poder
ver como
se realizan algunas cosas.
  #4 (permalink)  
Antiguo 06/05/2005, 05:23
 
Fecha de Ingreso: abril-2005
Mensajes: 14
Antigüedad: 19 años
Puntos: 0
ayuda para un primer esbozo

HOLA! SOY ESTUDIANTE de inf en francia y me piden hacer unas trabajo en php, del q no sabia nasa.yo hecho algunos tutoriales de php en internet pero hay determinadas cosas de las q no tengo ni idea de como usar

pues bien me piden agregar las siguiente funciones a otra llamada color q me dijo como se hacia un amigo del foro

alarmes_cn -> que da el valor (0,1,2,3) si une cn est pasado -> roje si resta 10% -> amarillo no le resta 10 por ciento -> verde
si error blanco

alarmes_visite -> si une visite est pasada roje
si queda 10% amarilla sino vert

alarme_equipement -> idem

y estos son los argimentos:
pot_cellule (en minutes), limite_potentiel(en minutes), potentiel_calendaire (en mois), date_application(date),
y sobre estos datos debo indicar el color de la seccion.


como ya comente en mensajes anteriores se trata de un programa de un taller de aeronautica, donde aparecen todas las aviones q pertenece
al taller, y asi se saben si estan en el aire, taller, o le queda poco para llegar
en un tabla se indica la celda de color correspondiente para dar la alarma

A mi solo se me pide lo q he comentado

hay q tener en cuenta el limite calendario y potencia

yo he intentado lo siguiente; pero no se si lo hago bien, os pido
q me indiqueis algunas de las cosas q pongo en comentarios, y me deis vuestra opinion
__________________________________________________ _____________

Ejercicio:
---------

// viendo tutoriales y demas con este codigo conecto

function conectar($servidor, $usuario, $password, $base_datos){
if (!($link=mysql_connect($servidor,$usuario,$passwor d))){
exit();
}
if(!(mysql_select_db($base_datos,$link))){
exit();
}
return $link;
}

$conexion = conectar("","usuariomysql","passmysql","basededato s");

// esta funcion nos devolvera el color


<?
function color($valor) {
if(!is_int($valor)) return false;
else if($valor<=3) {
switch($valor) {
case 0: return "WHITE"; break;
case 1: return "GREEN"; break;
case 2: return "YELLOW"; break;
case 3: return "RED"; break;
}
}
}

-------------------------------------------------------------------

// y ahora vamos a lo q me piden / q es lo q tengo q hacer al igual q la funcion de la q partimos

comentadme viendo la bd q os envie si estais de acuerdo en si creeis q es esta forma de tomar los datos la correcta para obtener lo q se me pide

los calculos de estado lo dejo con comentarios; pq quiero estar seguro de si la forma de proceder es la correcta en php; recordad q nunca he programado en php; alguna sugerencias si quereis ponerla de como lo hariais estaria bien
pero antes es mejor ver lo otro

Función:
-------

function alarmes_cn($id, $Date_app){


// aqui hago una variable sql, pero la instruccion sql no esta bien; con lo q he puesto deduzo lo q quiero para q veais lo q quiero; si me podrias indicar hacer esta, y ver como se hace la toma la datos en este ejemplo; yo haria las demas.

$sql = mysql_query("select Id_cn, Date from Cn",$conexion);


// he visto tutoriales; pero la unica forma de obtener datos q es visto es asi. q es de leer fichero; pero no se si es correcta; si no es la correcta podrias indicarmela en este ejemplo, yo la haria para el resto de codigo.

while($row = mysql_fetch_array($sql)){
$Date = $row["Date"];
}

// calcular estado - una vez q tenga la date podria trabajar con el argumento q recibe la funcion para calcular el estado, estais de acuerdo en lo datos q obtengo de un lado y ortro me llavan a podr calcular el estado?

return color($estado);
}


LLamada:
-------

//aqui idem a lo anterior; selecciono bien; la instruccion sql si me la dais en el primer ejemplo

aqui la modificaria yo

$sql = mysql_query("select Date_Appl from Concerne",$conexion);

while($row = mysql_fetch_array($sql)){
$Id_cn=$row["Id_cn"];
$Date_application = $row["Date_App"];
}

alarmes_cn($Id_cn, $Date_application)

// estas de acuerdo en q son los parametros q debo pasar, para obtener la fecha, o deberian ser de otra tabla?

pues eso con estas funciones proximas seria lo mismo pero viendo como

queda esta en la q me podrias indicar lo q os pregunto. yo haria lo demas ya q es mi tarea.

en las siguientes funciones si me comentais igual q en las anteriores si estais de acuerdo o no con los datos de las tablas q cogo para calcular lo q se me pide, seria aun cablazo:

---------------------------------------------------------------------

Función:
-------

function alarmes_visite($Id, $meses){

$sql = mysql_query("select Inmatriculation, DateV, DureeV, Cycle from Cdv",$conexion);

while($row = mysql_fetch_array($sql)){
$Inmatriculation=$row["Inmatriculation"];
$DureeV = $row["DureeV"];
$Cycle= $row["Cycle"];
}

//Con la DateV, DureeV, Cycle y la potentiel_calendaire en meses hallar estado

return color($estado);

}


LLamada:
-------

$sql = mysql_query("select Inmatriculation, Date from Passe",$conexion);

while($row = mysql_fetch_array($sql)){
$Inmatriculation=$row["Inmatriculation"];
$Date=$row["Date"];
}

$sql = mysql_query("select Id_TypeV, Cyclicite_Pot from TypeVisite",$conexion);

while($row = mysql_fetch_array($sql)){
$IdTypeV=$row["IdTypeV"];
$Cyclicite_Pot = $row["Cyclicite_Pot"];
}

// calcular el potentiel_calendaire (en meses) con la Date y la Cyclicite_pot

alarmes_visite($IdTypeV, $potentiel_calendaire);

---------------------------------------------------------------------------------

Función:
-------

function alarmes_equipement($Id, $minutos){

$sql = mysql_query("select Inmatriculation, Potentiel from Passe",$conexion);

while($row = mysql_fetch_array($sql)){
$Inmatriculation=$row["Inmatriculation"];
$Potentiel = $row["Potentiel"];
}

// ¿Es necesario saber Potencia, o se suprime lo de arriba?yo creo q si para tener en cuenta el tope

//Con los minutos se halla el estado para el limite_potentiel y la pot_cellule

return color($estado);

}


LLamada:
-------

$sql = mysql_query("select Inmatriculation, Pot_Cal, Pot_Duree from Equipement",$conexion);

while($row = mysql_fetch_array($sql)){
$Pot_Cal=$row["Pot_Cal"];
$Pot_Duree = $row["Pot_Duree"];
}


//Con la Pot_Cal y Pot_Duree se hallan los minutos


alarmes_equipement($Id_Eq, $pot_cellule);
alarmes_equipement($Id_Eq, $limite_potentiel);


-------------------------------------------------------------------------

// aqui cierro bd


mysql_free_result($sql);
mysql_close($conexion);
?>

__________________________________________________ _______________________


Espero vuestras ideas, sugerencias, comentarioq. comentamed si estais de acuerdo con los procedimiento, y los datos escogidos

gracias, es la primera vez q programo en php, ytoda ayuda es mucha
  #5 (permalink)  
Antiguo 06/05/2005, 05:25
 
Fecha de Ingreso: abril-2005
Mensajes: 14
Antigüedad: 19 años
Puntos: 0
ayuda para primer esbozo(bd)

esta es la bd:
-- Structure de la table `avion`
CREATE TABLE `avion` (
`Immatriculation` varchar(6) NOT NULL default '',
`Potentiel` int(7) NOT NULL default '0',
`IdType` int(5) NOT NULL default '0',
PRIMARY KEY (`Immatriculation`)
) ;
-- Structure de la table `cdv`
CREATE TABLE `cdv` (
`DateV` date NOT NULL default '0000-00-00',
`DureeV` int(6) NOT NULL default '0',
`Cycles` int(2) NOT NULL default '0',
`Descriptif` varchar(100) NOT NULL default '',
`Immatriculation` varchar(6) NOT NULL default '',
PRIMARY KEY (`DateV`,`Immatriculation`)
);
-- Structure de la table `cn`
CREATE TABLE `cn` (
`IdCn` int(5) NOT NULL default '0',
`Pays` varchar(15) NOT NULL default '',
`NSerie` varchar(30) NOT NULL default '',
`Texte` varchar(200) NOT NULL default '',
`Date` date NOT NULL default '0000-00-00',
`Revision` int(3) NOT NULL default '0',
`Type_Cn` varchar(15) NOT NULL default '',
PRIMARY KEY (`IdCn`)
) ;
-- Structure de la table `concerne`
CREATE TABLE `concerne` (
`Date_App` date NOT NULL default '0000-00-00',
`Cycle_App` int(6) NOT NULL default '0',
`Heure_App` int(6) NOT NULL default '0',
`Mois_Inter` int(6) NOT NULL default '0',
`IdCn` int(5) NOT NULL default '0',
`Immatriculation` varchar(6) NOT NULL default ''
) ;
-- Structure de la table `equipement`
CREATE TABLE `equipement` (
`IdEq` int(5) NOT NULL default '0',
`Desi` varchar(30) NOT NULL default '',
`Marque` varchar(30) NOT NULL default '',
`Type` varchar(10) NOT NULL default '',
`P/N` varchar(20) NOT NULL default '',
`S/N` varchar(20) NOT NULL default '',
`Pot_Cal` int(6) NOT NULL default '0',
`Pot_Duree` int(6) NOT NULL default '0',
`Immatriculation` varchar(6) NOT NULL default '',
PRIMARY KEY (`IdEq`)
) ;
-- Structure de la table `passe`
--
CREATE TABLE `passe` (
`Date` date NOT NULL default '0000-00-00',
`Potentiel` int(6) NOT NULL default '0',
`Atelier` varchar(30) NOT NULL default '',
`Immatriculation` varchar(6) NOT NULL default '',
`IdTypeV` int(5) NOT NULL default '0'
) ;
-- Structure de la table `possede`
CREATE TABLE `possede` (
`IdProp` int(5) NOT NULL default '0',
`Immatriculation` varchar(6) NOT NULL default ''
) ;
-- Structure de la table `progentr`
CREATE TABLE `progentr` (
`IdTypeA` int(5) NOT NULL default '0',
`IdTypeV` int(5) NOT NULL default '0'
) ;
-- Structure de la table `proprietaire`
CREATE TABLE `proprietaire` (
`IdProp` int(5) NOT NULL default '0',
`Nom` varchar(30) NOT NULL default '',
`Prenom` varchar(30) NOT NULL default '',
`AdrP` varchar(50) NOT NULL default '',
`AdrE` varchar(30) NOT NULL default '',
`Telephone` varchar(15) NOT NULL default '',
PRIMARY KEY (`IdProp`)
) ;
-- Structure de la table `revise`
--
CREATE TABLE `revise` (
`IdEq` int(5) NOT NULL default '0',
`IdTypeV` int(5) NOT NULL default '0'
);
-- Structure de la table `typeavion`
CREATE TABLE `typeavion` (
`IdTypeA` int(5) NOT NULL default '0',
`Marque` varchar(30) NOT NULL default '',
`Modele` varchar(30) NOT NULL default '',
PRIMARY KEY (`IdTypeA`)
) ;
-- Structure de la table `typevisite`
CREATE TABLE `typevisite` (
`IdTypeV` int(5) NOT NULL default '0',
`Cyclicite_pot` int(10) NOT NULL default '0',
`Nom` varchar(10) NOT NULL default '',
`Description` varchar(100) NOT NULL default '',
PRIMARY KEY (`IdTypeV`)
) ;
-- Structure de la table `user`
CREATE TABLE `user` (
`login` varchar(10) NOT NULL default '',
`password` varchar(10) NOT NULL default '',
`IdProp` int(5) NOT NULL default '0'
);
  #6 (permalink)  
Antiguo 09/05/2005, 02:05
 
Fecha de Ingreso: abril-2005
Mensajes: 14
Antigüedad: 19 años
Puntos: 0
codigo hecho

queria agradecersu ayuda a jam1138 q me facilitola funcion color y me abrio el camino

a final he usado este codigo, q os parece?

function conectar($servidor, $usuario, $password, $base_datos)
{
if (!($link=mysql_connect($servidor,$usuario,$passwor d)))
{
exit();
}
if(!(mysql_select_db($base_datos,$link)))
{
exit();
}
return $link;
}

$conexion = conectar("","usuariomysql","passmysql","basededato s");

<?

function color($valor) {
if(!is_int($valor)) return false;
else if($valor<=3)
{
switch($valor)
{
case 0: return "WHITE"; break;
case 1: return "GREEN"; break;
case 2: return "YELLOW"; break;
case 3: return "RED"; break;
}
}
}

function alarmes_cn($date_app){
$sql = mysql_query("select cn.IdCn,cn.Date,concerne.Date_App,concerne.IdCn from cn,concerne where cn.IdCn==concerne.IdCn && Concerne.Date_App=".$date_app,$conexion);
while($row = mysql_fetch_array($sql))
{
$Date =$row["Date"];
$Date_App= $row["Date_App"];
}
$Dias_totales=(strtotime($DateApp)-strtotime($Date))/(60*60*24);
$Dias_transcurridos=(strtotime(date("Y-m-d"))-strtotime($Date));
$Porcentaje_completado=$Dias_transcurridos*100/$Dias_totales;
$Porcentaje_restante=100-$Porcentaje_completado;
if ($Date_App==NULL)
{
return color(0);
}
else if ($Porcentaje_restante <= 0)
{
return color(3);
}
else if ($Porcentaje_restante <= 10)
{
return color(2);
}
else
{
return color(1);
}
}

function alarmes_visite($pot)
{
$sql = mysql_query("select cdv.DateV,cdv.DureeV,cdv.Immatriculation,passe.Dat e,passe.Immatriculation from cdv,passe where cdv.Immatriculation==passe.Immatriculation && passe.Potentiel=".$pot,$conexion);
while($row = mysql_fetch_array($sql))
{
$DateV = $row["DateV"];
$DureeV = $row["DureeV"];
$Date = $row["Date"];
}
$Dias_permanencia=(strtotime($Date)-strtotime($DateV))/(60*60*24);
$Porcentaje_permanencia=$Dias_permanencia*100/DureeV;
$Porcentaje_restante=100-$Porcentaje_permanencia;
if ($Porcentaje_restante <= 0)
{
return color(3);
}
else if ($Porcentaje_restante <= 10)
{
return color(2);
}
else
{
return color(1);
}
}

function alarmes_equipement($pc)
{
$sql = mysql_query("select avion.Immatriculation,equipement.Pot_Cal,equipemen t.Pot_Duree,equipement.Immatriculation from avion,equipement where avion.Immatriculation==equipement.Immatriculation && equipement.Pot_Cal=".$pc,$conexion);
while($row = mysql_fetch_array($sql))
{
$Pot_Duree = $row["Pot_Duree"];
}
$Porcentaje_pc=$pc*100/$Pot_Duree;
$Porcentaje_restante=100-Porcentaje_pc;
if ($Porcentaje_restante <= 0)
{
return color(3);
}
else
{
if ($Porcentaje_restante <= 10)
{
return color(2);
}
else
{
return color(1);
}
}
}


?>

saludos
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 00:18.