Jump to content


Photo

Mixing Dynamic w/ static variables


  • Please log in to reply
2 replies to this topic

#1 ibanez270dx

ibanez270dx
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 09 August 2006 - 07:15 PM

Hi,
I think I can work my way around a perticular problem, but I don't know how it would translate to code... This is what I want to do:

- First I want to extract some information from the database (pretty easy)

$sql = "SELECT * FROM downtime WHERE aircraft_id='$view_id' AND dwntime_year='$year' AND dwntime_month='$month' ORDER BY '$listorder'";

- Next I want to create an array for every selected row

$therows .= array(
<center>$dwntime_type</center>,
<center>$dwntime_date</center>,
<center>$dwntime_times</center>,
<center>$dwntime_hrs</center>,
<center>$dwntime_ata</center>,
<center>$dwntime_reason</center>,
<center>$dwntime_solution</center>,
<center>$dwntime_log</center>,
<center>$dwntime_log_by</center>);

- Then I want to take each array and put some static code next to it (I know this is wrong, but you kinda get an idea)

$display = "$therows(but only 1 row at a time) $excel->writeLine($therows)";

- That should be it. I am going to take that $display value and process it a little later in the script to make an Excel file.

Any help is greatly appreciated!


#2 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 09 August 2006 - 07:36 PM

1st
$therows[]=array(
"<center>$dwntime_type</center>",
"<center>$dwntime_date</center>",
"<center>$dwntime_times</center>",
"<center>$dwntime_hrs</center>",
"<center>$dwntime_ata</center>",
"<center>$dwntime_reason</center>",
"<center>$dwntime_solution</center>",
"<center>$dwntime_log</center>",
"<center>$dwntime_log_by</center>");
2nd
$x='';
foreach ($therows as $therow){
$x .= "<p>".implode('<br />',$therow)."</p>";
$y .= $excel->writeLine($therows)"; // i don't know what object do
}
echo $x;


#3 ibanez270dx

ibanez270dx
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 09 August 2006 - 08:39 PM

Thanks for your help! However, my script still doesn't work. Here it is in it's entirety - including the new stuff:

<?php

include("excelwriter.inc.php");

$view_id = "$_SESSION[aircraft_id]";
$datename = "AMA - $year - $month";
$filename = str_replace(' ', '', $datename);

include("connect.php");
$sql = "SELECT * FROM downtime WHERE aircraft_id='$view_id' AND dwntime_year='$year' AND dwntime_month='$month' ORDER BY '$listorder'";
$result = @mysql_query($sql,$connection) or die(mysql_error());

while ($row = mysql_fetch_array($result)) 
	{
	 $row_id = $row['row_id'];
	 $dwntime_type = ucfirst(stripslashes($row['dwntime_type']));
	 $dwntime_hrs = round($row['dwntime_hrs'], 2);
	 $dwntime_s = $row['dwntime_start'];
	 $dwntime_e = $row['dwntime_end'];
	 $dwntime_ata = $row['dwntime_ata'];
	 $dwntime_reason = stripslashes($row['dwntime_reason']);
	 $dwntime_solution = stripslashes($row['dwntime_solution']);
	 $dwntime_log = $row['dwntime_log'];
	 $dwntime_log_by = stripslashes($row['dwntime_log_by']);
	 $dwntime_day = $row['dwntime_day'];
	 $dwntime_month = $row['dwntime_month'];
	 $dwntime_year = $row['dwntime_year'];

	 $dwntime_times = "$dwntime_s - $dwntime_e";

	 $string = "$dwntime_year - $dwntime_month - $dwntime_day";
	 $dwntime_date = str_replace(' ', '', $string);
	 
	 $therows[]=array(
		"<center>$dwntime_type</center>",
		"<center>$dwntime_date</center>",
		"<center>$dwntime_times</center>",
		"<center>$dwntime_hrs</center>",
		"<center>$dwntime_ata</center>",
		"<center>$dwntime_reason</center>",
		"<center>$dwntime_solution</center>",
		"<center>$dwntime_log</center>",
		"<center>$dwntime_log_by</center>");
	}
 $excel=new ExcelWriter("$filename.xls");
	
	if($excel==false)	
		echo $excel->error;

		$x='';
	foreach ($therows as $therow)
		{
		 $x .= "<p>".implode('<br />',$therow)."</p>";
		 $y .= $excel->writeLine($therows);
		}
		
	$myArr=array("<b>XOJET AMA</b>","<b><i>$monthname, $year</i></b>");
	$excel->writeLine($myArr);

	$myArr=array(
"<font color=#FFFFFF>--------------------------</font>",
"<font color=#FFFFFF>--------------------------</font>",
"<font color=#FFFFFF>--------------------------</font>",
"<font color=#FFFFFF>--------------------------</font>",
"<font color=#FFFFFF>--------------------------</font>",
"<font color=#FFFFFF>--------------------------</font>",
"<font color=#FFFFFF>--------------------------</font>",
"<font color=#FFFFFF>--------------------------</font>",
"<font color=#FFFFFF>--------------------------</font>",);
	$excel->writeLine($myArr);

	$myArr=array(
"<center><b>Type</b></center>",
"<center><b>Date</b></center>",
"<center><b>Downtime</b></center>",
"<center><b>Hours Down</b></center>",
"<center><b>ATA</b></center>",
"<center><b>Discrepancy</b></center>",
"<center><b>Resolution</b></center>",
"<center><b>Logged</b></center>",
"<center><b>Logged By</b></center>");
	$excel->writeLine($myArr);
					
	$excel->open($filename.xls);
	echo "Data has been written to $filename.xls successfully. <a href=$filename.xls>Click here</a><br><hr size=1><br>$x<br><hr size=1><p>$y";


?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users