Problem with Array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
flyadvertising
Forum Newbie
Posts: 3
Joined: Wed May 26, 2010 1:07 pm

Problem with Array

Post 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.
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Problem with Array

Post 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?
flyadvertising
Forum Newbie
Posts: 3
Joined: Wed May 26, 2010 1:07 pm

Re: Problem with Array

Post 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"); 


?>

flyadvertising
Forum Newbie
Posts: 3
Joined: Wed May 26, 2010 1:07 pm

Re: Problem with Array

Post by flyadvertising »

Sorry, it did. I forgot to include the directory before the row result. Thanks!!!
Post Reply