if statement not typed good or PHP bug?
Posted: Sat Sep 01, 2007 7:44 am
hi. I'm using a small function I built. It always worked. Now it does not, I tried to test if all the variable work and they do. but the if statement does not seem to work. here is the code:-
what the function does is list all the pictures into a drop down menu. what what it does not work is the variable $sel_pic01 which stores the value selected="selected" if the picture name from html file and picture name from foreach loop matches in the if statement. Can anyone please help me? i really tried my best. thanks in advance
Code: Select all
function look_pic01() {
$filename = "../../beginpagina.html";
$fp = fopen($filename, "r") or die("Could'nt open $filename");
$g_pic01 = "";
$i = 0;
// get from line 20 picture name and store it in $g_pic01
while (!feof($fp)) {
$i++;
$line = fgets($fp, 1024);
if ($i === 20) {$g_pic01 = $line;}
}
$path = "../../pictures/";
echo "<select name=\"pic01\">";
echo "<option value=\"\"></option>";
foreach(glob($path.'*.jpg') as $e) {
$check_pic01 = basename($e);
$sel_pic01 = "";
if ($g_pic01 === $check_pic01) {$sel_pic01 = "selected=\"selected\"";}
echo "<option value=\"".$check_pic01."\" ".$sel_pic01.">".$check_pic01." ".$sel_pic01."</option>\n";
}
echo "</select>";
}