Foros del Web » Programando para Internet » PHP »

modificar lineas en archivo

Estas en el tema de modificar lineas en archivo en el foro de PHP en Foros del Web. hola que tal, tengo una duda y quisiera saber si uds me pueden ayudar y si es posible guiarme un poco en como hacerlo, tengo ...
  #1 (permalink)  
Antiguo 06/08/2009, 09:33
Avatar de lukas4  
Fecha de Ingreso: octubre-2008
Ubicación: frente al pc
Mensajes: 496
Antigüedad: 15 años, 6 meses
Puntos: 12
Pregunta modificar lineas en archivo

hola que tal, tengo una duda y quisiera saber si uds me pueden ayudar y si es posible guiarme un poco en como hacerlo, tengo este script:

Código script:
Ver original
  1. var tl;
  2. function onLoad() {
  3.   var eventSource = new Timeline.DefaultEventSource();
  4.   var bandInfos = [
  5.     Timeline.createBandInfo({
  6.         eventSource:    eventSource,
  7.         date:           "May 01 2009 00:00:00 GMT",
  8.         width:          "70%",
  9.         intervalUnit:   Timeline.DateTime.DAY,
  10.         intervalPixels: 100
  11.     }),
  12.     Timeline.createBandInfo({
  13.         showEventText:  false,
  14.         trackHeight:    0.5,
  15.         trackGap:       0.2,
  16.         eventSource:    eventSource,
  17.         date:           "May 01 2009 00:00:00 GMT",
  18.         width:          "30%",
  19.         intervalUnit:   Timeline.DateTime.MONTH,
  20.         intervalPixels: 200
  21.     })
  22.   ];
  23.   bandInfos[1].syncWith = 0;
  24.   bandInfos[1].highlight = true;
  25.   bandInfos[1].eventPainter.setLayout(bandInfos[0].eventPainter.getLayout());
  26.  
  27.   tl = Timeline.create(document.getElementById("my-timeline"), bandInfos);
  28.   Timeline.loadXML("prueba1.xml", function(xml, url) { eventSource.loadXML(xml, url); });
  29. }

y las lineas que ocupo modifiar son las de:

Código estas:
Ver original
  1. date:           "May 01 2009 00:00:00 GMT",
en ambas funciones, tenia pensado en crear el archivo e ir cambiando esos valores con unos resultados que obtendre de una busqueda a una BD, pero quisiera saber si existe la manera de modificar esas 2 lineas de alguna otra manera para asi no crear el archivo
  #2 (permalink)  
Antiguo 06/08/2009, 09:38
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: modificar lineas en archivo

Pues puedes agregarle la extensión PHP a ese archivo y usar <?php echo $fecha; ?> en esa parte para evitarte tener que abrir y generar el archivo.

Saludos.
  #3 (permalink)  
Antiguo 06/08/2009, 09:46
Avatar de lukas4  
Fecha de Ingreso: octubre-2008
Ubicación: frente al pc
Mensajes: 496
Antigüedad: 15 años, 6 meses
Puntos: 12
Respuesta: modificar lineas en archivo

ah caray, no comprendo, podrias explicarmelo en lenguaje newbie
  #4 (permalink)  
Antiguo 06/08/2009, 09:53
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: modificar lineas en archivo

Ese archivo me supongo es un archivo .js no? (de Javascript)
  #5 (permalink)  
Antiguo 06/08/2009, 09:55
Avatar de lukas4  
Fecha de Ingreso: octubre-2008
Ubicación: frente al pc
Mensajes: 496
Antigüedad: 15 años, 6 meses
Puntos: 12
Respuesta: modificar lineas en archivo

es un archivo html que genera una linea de tiempo, este es todo el codigo:

Código archivo HTML:
Ver original
  1. <title>Untitled Document</title>
  2.  
  3. <script src="http://simile.mit.edu/timeline/api/timeline-api.js" type="text/javascript"></script>
  4. <script>
  5. var tl;
  6. function onLoad() {
  7.   var eventSource = new Timeline.DefaultEventSource();
  8.   var bandInfos = [
  9.     Timeline.createBandInfo({
  10.         eventSource:    eventSource,
  11.         date:           "May 01 2009 00:00:00 GMT",
  12.         width:          "70%",
  13.         intervalUnit:   Timeline.DateTime.DAY,
  14.         intervalPixels: 100
  15.     }),
  16.     Timeline.createBandInfo({
  17.         showEventText:  false,
  18.         trackHeight:    0.5,
  19.         trackGap:       0.2,
  20.         eventSource:    eventSource,
  21.         date:           "May 01 2009 00:00:00 GMT",
  22.         width:          "30%",
  23.         intervalUnit:   Timeline.DateTime.MONTH,
  24.         intervalPixels: 200
  25.     })
  26.   ];
  27.   bandInfos[1].syncWith = 0;
  28.   bandInfos[1].highlight = true;
  29.   bandInfos[1].eventPainter.setLayout(bandInfos[0].eventPainter.getLayout());
  30.  
  31.   tl = Timeline.create(document.getElementById("my-timeline"), bandInfos);
  32.   Timeline.loadXML("prueba1.xml", function(xml, url) { eventSource.loadXML(xml, url); });
  33. }
  34. </script>
  35.  
  36.  
  37. </head>
  38.  
  39. <body onload="onLoad();" onresize="onResize();">
  40.  
  41. <div id="my-timeline" style="height:200px; border:1px solid #aaa"></div>
  42.  
  43.  
  44. </body>
  45. </html>

creo que ya entendi eso que me dices, podria enviarle unos datos mediante un post o un get y solamente sustituir esas lineas por que que venga en el post

Última edición por lukas4; 06/08/2009 a las 09:59 Razón: ya comprendi... creo
  #6 (permalink)  
Antiguo 06/08/2009, 11:11
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: modificar lineas en archivo

Exacto, pero para procesar el archivo cambialo como .php y solo rescatas el valor y lo indicas donde quieras, por ejemplo:
Código PHP:
Ver original
  1. <title>Untitled Document</title>
  2.  
  3. <script src="http://simile.mit.edu/timeline/api/timeline-api.js" type="text/javascript"></script>
  4. <script>
  5. var tl;
  6. function onLoad() {
  7.   var eventSource = new Timeline.DefaultEventSource();
  8.   var bandInfos = [
  9.     Timeline.createBandInfo({
  10.         eventSource:    eventSource,
  11.         date:           "<?php echo $fecha; ?>",
  12.         width:          "70%",
  13.         intervalUnit:   Timeline.DateTime.DAY,
  14.         intervalPixels: 100
  15.     }),
  16.     Timeline.createBandInfo({
  17.         showEventText:  false,
  18.         trackHeight:    0.5,
  19.         trackGap:       0.2,
  20.         eventSource:    eventSource,
  21.         date:           "May 01 2009 00:00:00 GMT",
  22.         width:          "30%",
  23.         intervalUnit:   Timeline.DateTime.MONTH,
  24.         intervalPixels: 200
  25.     })
  26.   ];
  27.   bandInfos[1].syncWith = 0;
  28.   bandInfos[1].highlight = true;
  29.   bandInfos[1].eventPainter.setLayout(bandInfos[0].eventPainter.getLayout());
  30.  
  31.   tl = Timeline.create(document.getElementById("my-timeline"), bandInfos);
  32.   Timeline.loadXML("prueba1.xml", function(xml, url) { eventSource.loadXML(xml, url); });
  33. }
  34. </script>
  35.  
  36.  
  37. </head>
  38.  
  39. <body onload="onLoad();" onresize="onResize();">
  40.  
  41. <div id="my-timeline" style="height:200px; border:1px solid #aaa"></div>
  42.  
  43.  
  44. </body>
  45. </html>

Saludos.
  #7 (permalink)  
Antiguo 10/08/2009, 10:30
Avatar de lukas4  
Fecha de Ingreso: octubre-2008
Ubicación: frente al pc
Mensajes: 496
Antigüedad: 15 años, 6 meses
Puntos: 12
hola hola que tal, yo de nuevo :D hice lo que me dijiste GatorV hice lo que me dijiste, pero tengo un problema, ya que al momento de mandarle el valor de la fecha, lo esta mandando vacio, estos son los codigos:

aqui envio el dato
Código PHP:
<?php
$link 
mysql_connect("localhost""root","");
mysql_select_db("MantoRedes",$link);

$myFile "prueba1.xml";
$fh=fopen($myFile,'w') or die("can't open file");

$query="SELECT fecha, dato, titulo FROM datostimeline WHERE nombre='lukas4'";
if(!
$busqueda=mysql_query($query,$link)){
    
mysql_error();
}
else{
    
$fecha[] = array();
    
$i=0;
    
$stringData="<?xml version=\"1.0\" encoding=\"utf-8\"?>".PHP_EOL."\t<data>".PHP_EOL."";
    
fwrite($fh,$stringData);
    while(
$row=mysql_fetch_array($busqueda)){
        
$fecha[$i]=$row['fecha'];
        
$stringData="\t<event start=\"".$row['fecha']."\" title=\"".$row['titulo']."\">".PHP_EOL."".$row['dato']."".PHP_EOL."\t</event>".PHP_EOL."";
        
fwrite($fh,$stringData);
        
$i++;
    }
}
$stringData="</data>";
fwrite($fh,$stringData);
fclose($fh);
print_r($fecha);
echo 
"<br>".$fecha[$i-1];
?>
<form action="timeline.php" method="post" id="forma">
    <input type="hidden" name="fecha" value="<?php echo $fecha[0];?>">
    <script language="javascript" type="text/javascript"><br>
    <!--
    document.getElementById("forma").submit();
    //-->
    </script>
</form>
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=timeline.php">
y acá lo recibo
Código PHP:
<?php
isset($_POST['fecha']) ? $fecha=$_POST['fecha'] : $fecha=date("M d Y H:i:s");
?>
<!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=utf-8" />
<title>Untitled Document</title>

<script src="http://simile.mit.edu/timeline/api/timeline-api.js" type="text/javascript"></script>
<script>
var tl;
function onLoad() {
  var eventSource = new Timeline.DefaultEventSource();
  var bandInfos = [
    Timeline.createBandInfo({
        eventSource:    eventSource,
        date:           "<?php echo $fecha?>",//"May 01 2009 00:00:00 GMT",
        width:          "70%", 
        intervalUnit:   Timeline.DateTime.DAY, 
        intervalPixels: 100
    }),
    Timeline.createBandInfo({
        showEventText:  false,
        trackHeight:    0.5,
        trackGap:       0.2,
        eventSource:    eventSource,
        date:           "<?php echo $fecha?>",//"May 01 2009 00:00:00 GMT",
        width:          "30%", 
        intervalUnit:   Timeline.DateTime.MONTH, 
        intervalPixels: 200
    })
  ];
  bandInfos[1].syncWith = 0;
  bandInfos[1].highlight = true;
  bandInfos[1].eventPainter.setLayout(bandInfos[0].eventPainter.getLayout());
  
  tl = Timeline.create(document.getElementById("my-timeline"), bandInfos);
  Timeline.loadXML("prueba1.xml", function(xml, url) { eventSource.loadXML(xml, url); });
}
</script>


</head>

<body onload="onLoad();" onresize="onResize();">
<br />
<div id="my-timeline" style="height:200px; border:1px solid #aaa"></div>


</body>
</html>
alguna idea del porque no esta enviando bien el dato?

oh ya lo hice trabajar, solo cambie la funcion de javascript, la funcion la puse en el onLoad y ya trabajo bien

Última edición por GatorV; 10/08/2009 a las 10:59
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 22:43.