0

Hi All,

I need to use the results of this query as an array to exclude files from a tree. The file and folder names that I enter into $exclude work fine but I can not seem to add the results from the query to the array. Below is the code that I am using. Can somebody please help me with this.

function home($exclude = '$testname|index.php|HR') {
	
$query = "SELECT * FROM doc WHERE status=0"; 
	 
$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
	$testname = "|".$row['full_path']."|";


}
$exclude_array = explode("|", $exclude);

Thank you,

Max

2
Contributors
5
Replies
9
Views
7 Years
Discussion Span
Last Post by trilithon
0

So $testname is going to be your array right?

Try:

$testname[] = "|".$row['full_path']."|";

Then you could use a foreach() to loop through the array and apply the explode() function

0

Can you please give me more info on how to use the $testname[] to insert the values into the $exclude variable.

Thank you

Max

0

I have changed the code as below. If I echo the results I see all the results that I am looking for but it only uses the latest record added in the explode command.

function home() {
	
$query = "SELECT * FROM doc WHERE status=0"; 
	 
$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
	$testname[] = $row['full_path'];
foreach ($testname as $value);
$exclude1 = "|"."index.php"."|".$value;


echo $exclude1;
}

 $exclude_array = explode("|", $exclude1);
0

That's because it's outside of the foreach loop. Add the explode function inside the foreach scope and it should work :D

0

Changed to the following and still getting the same result.

function home() {
	
$query = "SELECT * FROM doc WHERE status=0"; 
	 
$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
	$testname[] = $row['full_path'];
foreach ($testname as $value){
$exclude1 = "|"."index.php"."|".$value;
 $exclude_array = explode("|", $exclude1);
}
echo $exclude1;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.