473,327 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

how best to avoid brute-force looping?

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.

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
Apr 14 '06 #1
3 1453
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

Apr 14 '06 #2
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

Apr 14 '06 #3
On Sat, 15 Apr 2006 01:08:23 +0200, Henk Verhoeven wrote:
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.


Actually that's perfect, as I want the file to have that structure, and
I've already worked out a way to split the nubmers off the tags and create
a two-dimensional array....

--
o__
,>/'_ o__
(_)\(_) ,>/'_ o__
Yan Seiner, PE (_)\(_) ,>/'_ o__
Certified Personal Trainer (_)\(_) ,>/'_ o__
Licensed Professional Engineer (_)\(_) ,>/'_
Who says engineers have to be pencil necked geeks? (_)\(_)

Apr 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ryan N. | last post by:
Hello, I saw a brief blurb on this somewhere and am unable to recall where... In the context of Security, what are some best practices for handling -storing, locating, retrieving- database OLEDB...
10
by: Curious | last post by:
G'day all I'm working on a challenge given to me. The Javascript I have been given parses the user input in two ways. Firstly it generates two numbers. One is the sum of the CharCodes and the...
13
by: Monty | last post by:
I've been searching for guidance on which of the approaches used for skipping repetive links (e.g., link as normal text, link as alt text on invisible image, link with same forground and background...
131
by: Peter Foti | last post by:
Simple question... which is better to use for defining font sizes and why? px and em seem to be the leading candidates. I know what the general answer is going to be, but I'm hoping to ultimately...
14
by: Howard | last post by:
Hi, I recently had a problem where I decided to store objects in a vector. (Previously, I had always stored pointers in vectors). Well, naturally, when storing an object in a vector, using...
1
by: Rasika Wijayaratne | last post by:
Hello, Can I get feedback on these .NET coding best practices please. Thanks to Konrad Rudolph and Jon Skeet for the replies to my previous post on 'Writing Properties.' Thanks in advance to all...
12
by: Perre Van Wilrijk | last post by:
Hi there, When I started using VB6, I used to write classes with properties and functions as following ... Private lngf1 As Long Private strf2 As String Public Property Get f1() As Long...
2
by: Anil Pundhir | last post by:
What is the best way to pass data to a web service. The client(to send data) has .net environment and also the server on which the web service is hosted also has the .net environment. Should I...
9
by: david | last post by:
I have a class with some business-logic and with every roundtrip, I need an instance of this class, so I have to create it, every time again. That doesn't seem very efficient. I thought it would...
10
Khriskin
by: Khriskin | last post by:
As a warning, I'm self-taught so I have a bad habit of brute-forcing things out of ignorance. I've done some searching online and haven't found a solution, so I figured it couldn't hurt to ask you...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.