PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have some script that lists the contents of text files based on whether there is a specific letter "a, b, c..." within the text file. I am trying to include a elseif statement to tell the user of the page that there are no files if the letter does not comply...Here's the code:
//go through the array of files and list each
foreach ( $listings_array as $val ) {
$listings_file = file("admin/listings/listings/$val");
//create name variable (name = first line of listing_file array [k, c, e, w])
$name = $listings_file[0];
//if the first character of line 1 = the first character of the member's name list their posts
if ($name[0] == "k"){
$listMembers = array_shift($listings_file);
$listAddress = array_shift($listings_file);
$listDescription = implode('<BR>',$listings_file);
echo '<font class="LISTINGS" align="left"><b>'.$listAddress.'</font></b>';
echo '<font class="BODY_TEXT" align="left"><BR>'.$listDescription.'</font><br><HR class="HORIZ_RULE_BTM" width="95%" align="left">';
break;
}
elseif ($name[0] != "k"){
echo '<font class="BODY_TEXT_BOLD" align="left"><b>There are no available properties in this area.</font></b>';
break;
}
}
So if the letter is "k" it will list the file...The first IF statement works perfectly, the elseif isn't catching the exceptions...
well first! you would not need a elseif if you are like do this if this equals that and if not do this. just use "else".
second. have you tried to echo out what $name[0] is? maybe you are missing somthing simple.
third. please use php tags when posting php code. i do respect that you used code tags (as many new people do not) but php tags make it a lot easier to read.
edit: either you or a admin switch the tags, thanks whoever it was.
Two things I can see. First the break; statements will cause the loop to exit after the first loop, so you will never see anything but the first line. And