473,386 Members | 1,763 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,386 software developers and data experts.

algorithm help....

Hello there....

I hope there's someone who can help with one algorithm...I've been trying
the whole day....

I'm building my own FORM class and have a

function select(&$options, $name = "", $onchange = "")

there's also a var $selected to be called before ->select() because
someitmes I need some stuff to be selected by default....

I'm having a problem with algorithm after checking if ->selected is array or
not...

"not" part is done but "it is" part is giving me headaches....

i also have a var $selcted_what before ->selected to define what will be
selected ($keys or $values)...
So the pseudo code should be..

$options=Aray("test1","test2","test3","test4","tes t5");
$object->selected_what="values";
$object->selected=Array("test1","test2");
$object->select($options);

So the output should be select_box with test1 and test2 selected.....

or when

$object->selected_what="keys";
$object->selected=Array(1,2);
$object->select($options,"testing");

now it should have the "test2" and "test3" selected....

thanx for taking time to help....

respect....
Jul 16 '05 #1
8 2044

"point" <po***@caanNOSPAMproduction.com> schreef in bericht
news:bj*********@enews2.newsguy.com...

I'm building my own FORM class and have a

function select(&$options, $name = "", $onchange = "")

This is exactly how I started of my form class, before I realized it wasn't
very user friendly and it wasn't able to cope with new properties unless I
changed it (per example, what if you would need to define a style or a class
attribute in the <select /> tag?)

I rewrote the class methods to accept calls like:

$f->select(array('name'=>'selectionmenu','style'=>'fo nt-weight:bold',
'values'=>array('option 1'=>'1st option','option 2'=>'2nd option'),
'default'=>array('2nd option')));

which is a bit like the Perl CGI module works.

"not" part is done but "it is" part is giving me headaches....

i also have a var $selcted_what before ->selected to define what will be
selected ($keys or $values)...
So the pseudo code should be..


What you should do is create a class array variable which either contains
the keys and values of the $_POST or $_GET arrays, depending on the value of
the form's method attribute. When the name of the select menu exists in the
class array variable and its value matches one of the options, the default
selected option can be overwritten.
JW


Jul 16 '05 #2
"point" <po***@caanNOSPAMproduction.com> schreef in bericht
news:bj*********@enews2.newsguy.com...

I'm building my own FORM class and have a

function select(&$options, $name = "", $onchange = "")

This is exactly how I started of my form class, before I realized it wasn't
very user friendly and it wasn't able to cope with new properties unless I
changed it (per example, what if you would need to define a style or a class
attribute in the <select /> tag?)

I rewrote the class methods to accept calls like:

$f->select(array('name'=>'selectionmenu','style'=>'fo nt-weight:bold',
'values'=>array('option 1'=>'1st option','option 2'=>'2nd option'),
'default'=>array('2nd option')));
------------------
Well at a start I also did put the class tag init but as a coder I saw
that those 3 elements are all I need.....
Also happened with some other methods....I don't have a radiobutton tags
and some other because I didn't need them in my work by now(weird I know)..

So what seemd like to develope to messy stuff I killed at the start and
try not to write "the universal" class..but more what I need to help me at
my work....
------------------
which is a bit like the Perl CGI module works.

"not" part is done but "it is" part is giving me headaches....

i also have a var $selcted_what before ->selected to define what will be
selected ($keys or $values)...
So the pseudo code should be..


What you should do is create a class array variable which either contains
the keys and values of the $_POST or $_GET arrays, depending on the value
of
the form's method attribute. When the name of the select menu exists in
the
class array variable and its value matches one of the options, the default
selected option can be overwritten.
------------------
That what I usually do...i use like file.php?select=5
and in script before rendering with ->select I set the
$object->selected=$_GET['select]...

That works also fine but the problem is(I can belive I forgott to mention
that) is with MULTIPLE options....
------------------
Jul 16 '05 #3

"point" <po***@caanNOSPAMproduction.com> schreef in bericht
news:bj********@enews3.newsguy.com...

That works also fine but the problem is(I can belive I forgott to mention that) is with MULTIPLE options....


Then you will have to check whether the passed value is an array or not:

if (is_array($selected_options)) {
foreach ($selected_options as $option) {
// When $option equals one of the predefined options
// add 'selected' to the option
}
} else {
// Business as usual
}

BTW, your reply was hard to read because it wasn't quoted properly with the
'>' characters in front of the quoted lines. Please fix this.

JW

Jul 16 '05 #4
Hm... i tried a lots of variations but no luck....

Last version was like this:

if(is_array($this->selected))
{
foreach($this->selected as $_selectedKey=>$_selectedValue)
{
foreach($options as $value=>$output)
{
if($_selectedValue==$output)
print("\t\t<OPTION value=\"{$value}\"
SELECTED>{$output}</OPTION>\n");
else
print("\t\t<OPTION value=\"{$value}\">{$output}</OPTION>\n");
}
}
}
else { I got this part }

$options array has names of 150 people and as the $key there's
person_id(from database)....

$this->selected=Array(20,40)...

That means that only persons with id (option value) =20 and =40 should be
selected...

Hope you can help.....

Respect

"Janwillem Borleffs" <jw*@jwbfoto.demon.nl> wrote in message
news:3f***********************@news.euronet.nl...

"point" <po***@caanNOSPAMproduction.com> schreef in bericht
news:bj********@enews3.newsguy.com...

That works also fine but the problem is(I can belive I forgott to mention
that) is with MULTIPLE options....


Then you will have to check whether the passed value is an array or not:

if (is_array($selected_options)) {
foreach ($selected_options as $option) {
// When $option equals one of the predefined options
// add 'selected' to the option
}
} else {
// Business as usual
}

BTW, your reply was hard to read because it wasn't quoted properly with

the '>' characters in front of the quoted lines. Please fix this.

JW

Jul 16 '05 #5

"point" <po***@caanNOSPAMproduction.com> schreef in bericht
news:bj*********@enews4.newsguy.com...
Hm... i tried a lots of variations but no luck....
....
$options array has names of 150 people and as the $key there's
person_id(from database)....

$this->selected=Array(20,40)...


Since $this->selected is an 1-dimensional array, you can simplify your code
by using the in_array function:

foreach ($options as $value=>$output) {
if (is_array($this->selected)) {
if (in_array($value, $this->selected)) {
echo print("\t\t<OPTION value=\"$value\" SELECTED>$output</OPTION>\n");
} else {
print("\t\t<OPTION value=\"$value\">$output</OPTION>\n");
}
} else {
if ($value == $this->selected) {
echo print("\t\t<OPTION value=\"$value\" SELECTED>$output</OPTION>\n");
} else {
print("\t\t<OPTION value=\"$value\">$output</OPTION>\n");
}
}
}
JW

Jul 16 '05 #6

"Janwillem Borleffs" <jw*@jwbfoto.demon.nl> schreef in bericht
news:3f***********************@news.euronet.nl...

$options array has names of 150 people and as the $key there's
person_id(from database)....
.... echo print("\t\t<OPTION value=\"$value\"

SELECTED>$output</OPTION>\n");

Typo here, remove 'echo' in this and simulair lines:

foreach ($options as $value=>$output) {
if (is_array($this->selected)) {
if (in_array($value, $this->selected)) {
print("\t\t<OPTION value=\"$value\" SELECTED>$output</OPTION>\n");
} else {
print("\t\t<OPTION value=\"$value\">$output</OPTION>\n");
}
} else {
if ($value == $this->selected) {
print("\t\t<OPTION value=\"$value\" SELECTED>$output</OPTION>\n");
} else {
print("\t\t<OPTION value=\"$value\">$output</OPTION>\n");
}
}
}
JW

Jul 16 '05 #7
Believe it or not when I was reading your answer my php_manual was on
is_array() function.....

I often used that function but how did sliped my mind in this case will
remain a mistery... :))

So everything is working :)

respect to you and thanx for your time to help....

You're one of few people I see here helping others on regular basis.....

Once again thanx....
"Janwillem Borleffs" <jw*@jwbfoto.demon.nl> wrote in message
news:3f***********************@news.euronet.nl...

"point" <po***@caanNOSPAMproduction.com> schreef in bericht
news:bj*********@enews4.newsguy.com...
Hm... i tried a lots of variations but no luck....
...

$options array has names of 150 people and as the $key there's
person_id(from database)....

$this->selected=Array(20,40)...


Since $this->selected is an 1-dimensional array, you can simplify your

code by using the in_array function:

foreach ($options as $value=>$output) {
if (is_array($this->selected)) {
if (in_array($value, $this->selected)) {
echo print("\t\t<OPTION value=\"$value\" SELECTED>$output</OPTION>\n"); } else {
print("\t\t<OPTION value=\"$value\">$output</OPTION>\n");
}
} else {
if ($value == $this->selected) {
echo print("\t\t<OPTION value=\"$value\" SELECTED>$output</OPTION>\n"); } else {
print("\t\t<OPTION value=\"$value\">$output</OPTION>\n");
}
}
}
JW

Jul 16 '05 #8
Yeah I noticed the echoes when I was reading the answer....I figured that
was a typo.....

:))
"point" <po***@caanNOSPAMproduction.com> wrote in message
news:bj********@enews4.newsguy.com...
Believe it or not when I was reading your answer my php_manual was on
is_array() function.....

I often used that function but how did sliped my mind in this case will
remain a mistery... :))

So everything is working :)

respect to you and thanx for your time to help....

You're one of few people I see here helping others on regular basis.....

Once again thanx....
"Janwillem Borleffs" <jw*@jwbfoto.demon.nl> wrote in message
news:3f***********************@news.euronet.nl...

"point" <po***@caanNOSPAMproduction.com> schreef in bericht
news:bj*********@enews4.newsguy.com...
Hm... i tried a lots of variations but no luck....

...

$options array has names of 150 people and as the $key there's
person_id(from database)....

$this->selected=Array(20,40)...


Since $this->selected is an 1-dimensional array, you can simplify your

code
by using the in_array function:

foreach ($options as $value=>$output) {
if (is_array($this->selected)) {
if (in_array($value, $this->selected)) {
echo print("\t\t<OPTION value=\"$value\"

SELECTED>$output</OPTION>\n");
} else {
print("\t\t<OPTION value=\"$value\">$output</OPTION>\n");
}
} else {
if ($value == $this->selected) {
echo print("\t\t<OPTION value=\"$value\"

SELECTED>$output</OPTION>\n");
} else {
print("\t\t<OPTION value=\"$value\">$output</OPTION>\n");
}
}
}
JW


Jul 16 '05 #9

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

Similar topics

6
by: Jack Smith | last post by:
Hello, any help appreciated with following problem. I figured out the algorithm (I think), just having trouble proving it is optimal. Suppose we are given n tasks each of which takes 1 unit...
16
by: cody | last post by:
I have to write an algorithm with must ensure that objects are put in buckets (which are always 4 in size). The objects have two properties: A and B. It is not allowed that in a bucket are objects...
17
by: savesdeday | last post by:
In my beginnning computer science class we were asked to translate a simple interest problem. We are expected to write an algorithm that gets values for the starting account balance B, annual...
2
by: ben | last post by:
hello, i'm following an algorithm book and am stuck on an early excersise in it, not because of the c programming side of it or even the algorithm side of it, i don't think, but because of maths....
113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
6
by: Bernie Yaeger | last post by:
I need a little help with an algorithm. Let's say I have an array with 15 items. I want to find "Fern" where there are "Able", "Me Also", "Zimmerman", etc in no particular order. Forget about...
10
by: Nemok | last post by:
Hi, I am trying to write an additive encryption algorithm in C++ that will encrypt a text by adding a random numer to each character in a string. The code looks similar to this: for(int...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
6
by: StephQ | last post by:
I need to implement an algorithm that takes as input a container and write some output in another container. The containers involved are usually vectors, but I would like not to rule out the...
1
by: almurph | last post by:
Hi everyone, Concerning the Needleman-Wunsch algorithm (cf. http://en.wikipedia.org/wiki/Needleman-Wunsch_algorithm) I have noticed a possible loop. Inside the algorithm there is an...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.