I’m trying to figure out how to make the code below work.
<?php
$var = $fn_category = array (2);
if ($var == TRUE){
include ‘/home/express/public_html/news/news.php’;
}
else {
echo “Sorry there is no news at this time”;
}
?>
Now when array(2) has content it displays but when array (2) is FALSE or empty my else echo doesn’t display. I’ve tried several different ways just can’t quite get it.
array(2); cannot be false. It has content. The value 2. (the array() language construction does not take a size parameter. Anything included in the array definition is data. PHP arrays have no fixed size.
When there is no data for array(2) nothing displays on the page. When there is data for array(2) of course it displays and the code for this is below.
<?php
$fn_category = array (2)
include ‘/home/express/public_html/news/news.php’;
?>
But what I want is that when there is no data to display for array(2) the page displays alternate data. So why wouldn’t the below code work? Or how can I accomplish what I’m trying to do.
<?php
if ($fn_category = array (2)) {
include ‘/home/express/public_html/news/news.php’;
} else {
echo “Sorry there is no news at this time”;
}
?>
Data for this array is stored in a flat file. array (0) = category id
Each category has it’s news page(s), so when there is no news in a category I want the script to say so instead of being blank.
I’m not the sharpest pin in the haystack, I understand about the array always having data. I guess I have to find in the script where I can accomplish this as I understand I’m not going to get it done at the web document level.
mkay, so delimited by |<| and ignoring the first line…
<?php
$news = array();
$f = fopen('path/to/flatfile');
fgets($f); // Get rid of line 1.
while($line = fgets($f)) {
$news[] = explode("|<|",$line);
}
// $news is now a populated array of elements containing your news data.
if(count($news) == 0) {
//There was no data.
} else {
//There was.
}