Need Help with PHP code
Posted: Tue Oct 13, 2009 9:10 am
Hi I'v recently installed a website but got warnings on site not sure how to fix.
Page titled menuvertical.php
<?php
set_time_limit(120);
//echo $number_articles_menu;
//echo "random=".$random_list;
//$file_handle = fopen(ARTICLES_DIR.".txt", "rb");
//echo ARTICLES_DIR;
$results = array();
// create a handler for the directory
$handler = opendir(ARTICLES_DIR);
// keep going until all files in directory have been read
$num_art=0;
while ($file = readdir($handler)) {
// if $file isn't this directory or its parent,
// add it to the results array
if ($file != '.' && $file != '..') {
$results[] = $file;
//title here
$file_handle = fopen(ARTICLES_DIR.$file, "rb");
$i=0;
$letCount=-1;
while (!feof($file_handle) || $i==0) {
$line_of_text = fgets($file_handle);
$line_of_text = trim($line_of_text);
if ($i==0 && $letCount==-1) {
$letCount = strlen($line_of_text);
if ($letCount>5) {
$i=1;
$title=$line_of_text;
break;
} else {
$i=0;
$letCount=-1;
} //if $letCount
} //if i & letcount
} //while !feof
fclose($file_handle);
$desc[]=$title;
//title here
$num_art++;
}
}
// tidy up: close the handler
closedir($handler);
echo "<ul>";
if ($num_art>$number_articles_menu) {
if ($random_list==1) {
$low = 0;
$high = $number_articles_menu-1;
$step = 1;
$numbers = range($low,$high,$step);
shuffle($numbers);
//print_r($numbers);
$inum=0;
while ($inum<=$high) {
echo "<li><a href=\"article-".clean_url(substr($results[$numbers[$inum]],0,-3)).".html\" alt=\"".$desc[$numbers[$inum]]."\">" . $desc[$numbers[$inum]] ."</a></li>";$inum++;
}
} else {
$inum=0;
while ($inum<=$num_art-3) {
echo "<li><a href=\"article-".clean_url(substr($results[$inum],0,-3)).".html\" alt=\"".$desc[$inum]."\">" . $desc[$inum] ."</a></li>";$inum++;
}
} //random
} else {
$inum=0;
while ($inum<=$num_art-3) {
echo "<li><a href=\"article-".clean_url(substr($results[$inum],0,-3)).".html\" alt=\"".$desc[$inum]."\">" . $desc[$inum] ."</a></li>";$inum++;
}
}
echo "</ul>";
?>
This is the warnings I'm getting.
Warning: Wrong parameter count for range() in /home/mandp0/public_html/computer/menuvertical.php on line 88
Warning: shuffle() expects parameter 1 to be array, null given in /home/mandp0/public_html/computer/menuvertical.php on line 89
If anyone could help I would greatly appreciate it.
Thanks
mandp
Page titled menuvertical.php
<?php
set_time_limit(120);
//echo $number_articles_menu;
//echo "random=".$random_list;
//$file_handle = fopen(ARTICLES_DIR.".txt", "rb");
//echo ARTICLES_DIR;
$results = array();
// create a handler for the directory
$handler = opendir(ARTICLES_DIR);
// keep going until all files in directory have been read
$num_art=0;
while ($file = readdir($handler)) {
// if $file isn't this directory or its parent,
// add it to the results array
if ($file != '.' && $file != '..') {
$results[] = $file;
//title here
$file_handle = fopen(ARTICLES_DIR.$file, "rb");
$i=0;
$letCount=-1;
while (!feof($file_handle) || $i==0) {
$line_of_text = fgets($file_handle);
$line_of_text = trim($line_of_text);
if ($i==0 && $letCount==-1) {
$letCount = strlen($line_of_text);
if ($letCount>5) {
$i=1;
$title=$line_of_text;
break;
} else {
$i=0;
$letCount=-1;
} //if $letCount
} //if i & letcount
} //while !feof
fclose($file_handle);
$desc[]=$title;
//title here
$num_art++;
}
}
// tidy up: close the handler
closedir($handler);
echo "<ul>";
if ($num_art>$number_articles_menu) {
if ($random_list==1) {
$low = 0;
$high = $number_articles_menu-1;
$step = 1;
$numbers = range($low,$high,$step);
shuffle($numbers);
//print_r($numbers);
$inum=0;
while ($inum<=$high) {
echo "<li><a href=\"article-".clean_url(substr($results[$numbers[$inum]],0,-3)).".html\" alt=\"".$desc[$numbers[$inum]]."\">" . $desc[$numbers[$inum]] ."</a></li>";$inum++;
}
} else {
$inum=0;
while ($inum<=$num_art-3) {
echo "<li><a href=\"article-".clean_url(substr($results[$inum],0,-3)).".html\" alt=\"".$desc[$inum]."\">" . $desc[$inum] ."</a></li>";$inum++;
}
} //random
} else {
$inum=0;
while ($inum<=$num_art-3) {
echo "<li><a href=\"article-".clean_url(substr($results[$inum],0,-3)).".html\" alt=\"".$desc[$inum]."\">" . $desc[$inum] ."</a></li>";$inum++;
}
}
echo "</ul>";
?>
This is the warnings I'm getting.
Warning: Wrong parameter count for range() in /home/mandp0/public_html/computer/menuvertical.php on line 88
Warning: shuffle() expects parameter 1 to be array, null given in /home/mandp0/public_html/computer/menuvertical.php on line 89
If anyone could help I would greatly appreciate it.
Thanks
mandp