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

Recommended Answers

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

Jump to Post

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

Jump to Post

All 5 Replies

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

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

Thank you

Max

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

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

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;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.