View Full Version : variable problem,,,

06-30-2005, 10:23 AM
Code is;


$sql = " select * from test order by headnum ,arrangenum ";
$test_result = mysql_query($sql);
for ($i=0; $row=mysql_fetch_array($test_result); $i++)
$g_date = date("Y-m-d H:i:s", $row[g_date]);

//file copy upgrade
$file1 = "";
$file1_source = "";
echo "<'$target'>"; //no 1
if ($row[files] && file_exists("$test[dir]/$row[files]")) {
echo "<'$target'>"; // no 2

no 1 line show right result, but no 2 line shows nothing.

Any comment would be appreciated.

06-30-2005, 10:40 AM
Shouldn't target be 'c:/test' ?

06-30-2005, 10:54 AM
Shouldn't target be 'c:/test' ?

No, target should be 'c:\test'.

And, I tried

But same result.

06-30-2005, 12:47 PM
1. $target is incorrect. Should be either C:\test or a relative path. I also see no reason for this to create the errors.
2. $test is undefined.
3. SQL may return an empty row, though I say its not simply due to the fact your first echo is returned. It is possible however, that the information is not complete.
4. Is there a reason why you have this as: "<'$target'>"? Interior commas are probably unessessary, also assuming this is for XML generation.

Also, you have an odd way of setting up your loop. Under the assumption that the data should always be present, you should just use:

while ($row = mysql_fetch_array($test_result))
// Stuff, no $i added for your arrays though...

Edit: The last point is possibly the main cause of this, as you are not specifying where its location within the loop is. As well, if this is not the cause, its due to the attempt to grab $test[dir], which I assume is supposed to be $row['dir']. These two fixes should cause this to function correctly.

06-30-2005, 08:32 PM
Well aren't backslashes windows only?
In the code you are using the forward slash


so you might stick to on type of slash (preferably the unix one as it will work on unix systems and on windows).
In double quotes the "\" escapes some things but a "\t" inserts a horizontal tab so it's probably not what you want. If you wan't to use a backslash you should escape it so it would be "c:\\test".
The loop is ok. It doesn't matter if it's a for or a while loop (though you don't usually use for loops for that).

07-01-2005, 08:04 AM
copying files $souce/$testfiles to $target/$testfiles


while ($row=mysql_fetch_array($test_result))
$file1 = "";
$file1_source = "";
if ($row[file_name1] && file_exists("$source/$row[file_name1]")) {
$file1 = substr(md5($i),0,8) . "_" . $row[s_file_name1];
$file1_source = $row[s_file_name1];
echo "a-$file1"; <---- no1
@copy("$source/$row[file_name1]", "$target/data/file/$target_dir/$file1");
@chmod("$target/$row[file_name1]", 0606);
/* if (is_file($target/$row[file_name1])) {
return echo $target/$row[file_name1]; } */
} else {
echo $row[s_file_name1];
$file1 = substr(md5($i),0,8) . "_" . $row[s_file_name1];
$file1_source = $row[s_file_name1];
echo "d-$file1"; <---no2
@copy("$source/$row[file_name1]", "$target/$row[file_name1]");
@chmod("$target/data/file/$target_dir/$file1", 0606);
/* if (is_file($target/$row[file_name1])) {
return echo $target/$row[file_name1];
} */


No1 shows nothing.
No 2 shows
d-:: eccbc87e
e-:: /test-source
f-:: /test-source/file_name/eccbc87e_

Any comment would be appreciated.

07-01-2005, 05:09 PM
Dear Fou_Lu and marek_mar,

Thanks alot for your kind comments.

I've solved this by changing if sentence.