You are here: Re: Strange results from foreach loop « PHP Programming Language « IT news, forums, messages
Re: Strange results from foreach loop

Posted by brephophagist on 10/26/06 19:34

Seems like you should change $number here:

> elseif ($question_count < $number) {
> $status = "_blank";
> }
>
> elseif ($question_count > $number) {
> $status = "";
> }

to some fixed question count you want to use to determine whether the
button should be "inactive" or not.
i.e.

$question_count = "3";
$question_id = "2";

$count_inactive_threshold = "2";

foreach (range(1, 5) as $number) {

if ($question_id == $number) {
$status = "_selected";
}

elseif ($question_count < $count_inactive_threshold) {
$status = "_blank";
}

elseif ($question_count >= $count_inactive_threshold) {
$status = "";
}
echo "q" . $number . $status . ".gif<br>";

}


You're comparing a variable that doesn't change in the loop against
your iterator... from your description "based
on the count of questions in a database" it seems you should be
comparing a constant / unchanging variable against another variable
pulled from the database.

HTH--
jason

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация