You are here: Re: trying to make a loop, cant figure it out « All PHP « IT news, forums, messages
Re: trying to make a loop, cant figure it out

Posted by MS on 09/28/19 11:49

You will require something on these lines... It has not been tested
though...

<?php
$string = "01101";
$wordlist = array("pos1","pos2","pos3","pos4","pos5");
$td = 0;

echo "<table>";
for($i=0; $i < strlen($string); $i++){
if(substr($string,$i,1) == "1"){
echo ($td == 0) ? "<tr><td>" : "<td>";
echo $wordlist[$i];
$td++;
if($td == 2){
$td=0;
echo "</td></tr>";
}else{
echo "</td>";
}
}
}

// cleanup table
echo ($td == 1) ? "<td>&nbsp;</td></tr>" : "";

echo "</table>";

?>


--
----------------------------------------------------------------------------
http://www.myclubweb.co.uk - The Home of Club Websites
----------------------------------------------------------------------------


"Kentor" <kentor@gmail.com> wrote in message
news:1149449562.998031.175330@f6g2000cwb.googlegroups.com...
> hello, im trying to make a little loop, but i cant figure it out... i
> have a string with a bunch of 1s and 0s in it: 110101010101111010101
> ... i need to count the number of 1s divide it by 2 and make a table
> with 2 columns and then for every one, depending on its position in the
> string i need to output a word and then go to the next 1 and output a
> dif word....
>
> its amenities, winter activities and summer activities for cottages
> that i store in my db with 1s and 0s when its a 1 the amenitie or
> whatever exists when its a 0 then it doesent exist...
>
> an example of the kind of table that i need is here:
> http://www.chaletsauquebec.com/FicheChalet.aspx?IdChalet=2011
>

 

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

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