You are here: Re: how best to avoid brute-force looping? « PHP Programming Language « IT news, forums, messages
Re: how best to avoid brute-force looping?

Posted by Henk Verhoeven on 04/15/06 02:08

Hi Captain,

Something like this:?

for ($count=1; $count<$max; $count++) {
$subArray = $myArray[$count];
print "
<td><input name='brgf$count' type=text value='$subArray[brgf]'
maxLength='5' size='5'></td>
> <td><input name='brgt$count' type=text value='$subArray[brgt]'
maxLength='5' size='5'></td>
(..)

Of course your array would have to be two-dimensional like:
$myArray[1]['brgf'] = 0.000000;
$myArray[1]['brgt'] = 1.000000;
$myArray[1]['axa'] = 1;
$myArray[2]['brgf'] = 2.000000;
$myArray[2]['brgt'] = 2.000000;

Greetings,

Henk.

Captain Dondo wrote:
> Captain Dondo wrote:
>
>> First of all, thanks for the serialize pointer in an earlier thread.
>> That looks like it's the ticket.
>>
>> Now, I have a style/php question. (I am a C hacker by background, and
>> thus everything is a loop... But PHP is different...)
>>
>> OK, I write out my array and read it back in. It comes in thus:
>>
>> Array (
>> [currentField] => 103
>> [brgf1] => 0.000000
>> [brgt1] => 1.000000
>> [axa1] => 1
>> [brgf2] => 2.000000
>> [brgt2] => 2.000000
>> [axa2] => 2
>> [axb2] => 2
>> [axc2] => 2
>> [axd2] => 2
>> [brgf3] => 2.000000
>> [brgt3] => 3.000000
>> [axa3] => 2
>> [axb3] => 2
>> [axc3] => 2
>> [axd3] => 2
>>
>> ....
>> ....
>> )
>>
>> Basically each line consists of two bearings and 4 true/false
>> switches. The line number in the schedule is apended to the name of
>> the field.
>
>
> OOPS! Looks like I left out a line....
>
> I need to output this to a webpage, using input fields like this:
>
> <tr>
> <td>%d</td>
> <td><input name='brgf%d' type=text value='%f' maxLength="5" size="5"></td>
> <td><input name='brgt%d' type=text value='%f' maxLength="5" size="5"></td>
> <td><input name='axa1' type='hidden' value='%d' size='3'
> readonly='readonly'>
> </tr>
>
>>
>> In my C mind, this calls for a loop, bruteforcing our way and
>> appending the counter to each name....
>>
>> But I *know* there is a more elegant PHP way to do this. While it
>> makes sense in C, it just looks fugly in PHP....
>>
>> As I use PHP to generate the field names, I can change those if it
>> makes things easier....
>>
>> Thanks,
>>
>> --Yan

 

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

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