Page 1 of 1

Problem with Array

Posted: Wed May 26, 2010 1:12 pm
by flyadvertising
This line of code works fine in my app:
$ziper->addFiles(array("uploads/epidemiology_4.ppt","uploads/epidemiology_1.ppt"));

However, I am trying to populate the array dynamically via a MySQL database call. I can call the database and create a string variable, but inserting the variable into the code above fails. Any advice would be great.

Thanks in advance.

Re: Problem with Array

Posted: Wed May 26, 2010 1:19 pm
by flying_circus
flyadvertising wrote:Any advice would be great.
Don't create a string variable, create an array and pass it to your addFiles() method.

Code: Select all

<?php
  $arFiles = array();

  $results = mysql_query($querystring);

  while($row = mysql_fetch_assoc($results)) {
    $arFiles[] = $row['filename'];
  }

  $ziper->addFiles($arFiles);
?>
Can you post the code that you've tried?

Re: Problem with Array

Posted: Wed May 26, 2010 1:27 pm
by flyadvertising
That didn't populate the array :(

Here's the code (including your suggestion):

Code: Select all

<?php
  
//connection
$usn = 0;
$arFiles = array();

$query= "SELECT builds.bUser, builds.bSession, builds.bSlides, slides.sJpg, slides.sID, slides.sPpt FROM builds LEFT JOIN slides ON builds.bSlides = slides.sID WHERE (builds.bUser = '" . $pid . "' AND builds.bSession = '" . $sid . "') ORDER BY builds.bSlides DESC";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
	if ($usn != $row['bSlides'])
	{
	$arFiles[] = $row['sPpt'];
	}
	$usn = $row['bSlides'];
} 

mysql_close($conn);


include("zip.lib.php"); 
$ziper = new zipfile(); 
$ziper->addFiles($arFiles);  //array of files 
$ziper->output("myzip.zip"); 


?>


Re: Problem with Array

Posted: Wed May 26, 2010 1:44 pm
by flyadvertising
Sorry, it did. I forgot to include the directory before the row result. Thanks!!!