www_puertoricoautoforo_com
asked on
foreach as - error in my PHP function, only 37 lines long, please look.
This php function searches for sequentially named images and echo's them out. It used to work.. Maybe the command was depreciated or my syntax is wrong? I always get an error on line 26, that's the line that simply says "AS"
For some reason "AS" keeps giving me a php error
For some reason "AS" keeps giving me a php error
<?php
$part='PART1';
$webserver='/home/webmaster/domains/website/public_html/media/import/';
function pictureTest($input)
{
$link = mysql_connect('localhost', 'dbuser', 'dbpassword');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
if (!mysql_select_db('test')) {
die('Could not select database: ' . mysql_error());
}
$result = mysql_query("SELECT image FROM test WHERE part = '$input'");
if (!$result) {
die('Could not query:' . mysql_error());
$input=mysql_result($result, 0, 'image');
mysql_close($link);
return $input;
}
{
global $webserver;
$p = "";
foreach(glob($webserver.$input.'*.jpg')
as
$filename) {
$p .= "," . str_replace($webserver,"",$filename); }
$p = substr($p,1,strlen($p) - 1);
return $p;
}
}
echo pictureTest("PART1");
?>
Are you missing an else somewhere around line 22?
ASKER
I tried just now putting an "else" there but it didn't work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Warning: Invalid argument supplied for foreach() in /home/webmaster/domains/we bsite.com/ public_htm l/csv_fixe r/test2.ph p on line 22
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Before your foreach statement add the following line
print_r(glob($webserver.$i nput.'*.jp g'));
That way you will see if the glob function is returning an array - which is what the foreach loop is expecting - and seemingly not getting
print_r(glob($webserver.$i
That way you will see if the glob function is returning an array - which is what the foreach loop is expecting - and seemingly not getting
ASKER
If I delete the
9: { //WHY IS THIS LINE HERE
and the
17: { //WHY IS THIS LINE HERE
it still gives me an error on line 26
Warning: Invalid argument supplied for foreach() in /home/webmaster/domains/ra ceonusa.co m/public_h tml/csv_fi xer/test2. php on line 26
9: { //WHY IS THIS LINE HERE
and the
17: { //WHY IS THIS LINE HERE
it still gives me an error on line 26
Warning: Invalid argument supplied for foreach() in /home/webmaster/domains/ra
Hi,
Didn't say that would fix the problem - just wondered why it was there.
Did you get a response from the print_r statement?
Didn't say that would fix the problem - just wondered why it was there.
Did you get a response from the print_r statement?
I would not be able to access a directory the way you are from a web page. The first line below works for on my server on a web page. I'm guessing $input is a subdirectory. See if the second line might work for you.
foreach(glob('media/import/*.jpg') as $filename)
foreach(glob('media/import/$input/*.jpg') as $filename)
I'm sure that error message refers to glob($webserver.$input.'*. jpg'). Either $webserver or $input has a bad value or maybe your host has changed permissions on Apache so you can't access that directory that way.