Re: [PHP-DB] Arrays and forms

2003-01-14 Thread Jason Wong
On Wednesday 15 January 2003 03:23, Mignon Hunter wrote:
> Hello list,
>
> I submitted this problem earlier but got no response so I thought I'd
> elaborate.
>
> The code below successfully displays all of the problems from the db.
> Based on what is chosen here, needs to go into another table in the db
> along with a customer tracking id.
>
> for($knt = 0;$row = mysql_fetch_row($res3); $knt++)
>   {
>   $cat_detail = $row[0];
>   echo "   \"$cat_detail\">  $cat_detail "
>   ." Highvalue=\"1\">"
>   ." Medvalue=\"2\">"
>   ." Lowvalue=\"3\">"
>   ." Yes
>   ";
>   }
>
> When this page is submitted, I can successfully capture $prob[]  - but I
> am having no luck in pulling the corresponding $level[] (if one was
> checked).  So my form - once submitted - may look like:
>
> Problem one   (no priority picked)
> Problem two   High priority
> Problem three Low priority
>
> My $prob[] would be:  My $level[] would be:
>
> $prob[0]: Problem one $level[0]:  High
> $prob[1]: Problem two $level[1]:  Low
> $prob[2]: Problem three
>
> So as you can see my second problem does not correctly correspond to the
> correct priority.  The first (or all) element(s) in the level array may
> be null.

The reason is that:

1) unchecked checkboxes do not make it into php
2) because you're not specifying an index for the array (level[]), php will 
create it for you automatically

So instead of using just 

  name="level[]"

specify the level explicitly:

  name="level[0]", name="level[1]", etc

NB you should do the same for prob[] as well.

Having done that then in your example you should get something like:


 $prob[0]: Problem one
 $prob[1]: Problem two  $level[1]:  High
 $prob[2]: Problem three$level[2]:  Low

NB that $level[0] is undefined.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *


/*
Harp not on that string.
-- William Shakespeare, "Henry VI"
*/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] Arrays and forms

2003-01-14 Thread Mignon Hunter
Hello list,

I submitted this problem earlier but got no response so I thought I'd
elaborate.

The code below successfully displays all of the problems from the db. 
Based on what is chosen here, needs to go into another table in the db 
along with a customer tracking id.

for($knt = 0;$row = mysql_fetch_row($res3); $knt++)
{
$cat_detail = $row[0];
echo "  $cat_detail "
." High "
." Med "
." Low "
." Yes
";
}

When this page is submitted, I can successfully capture $prob[]  - but I
am having no luck in pulling the corresponding $level[] (if one was
checked).  So my form - once submitted - may look like:

Problem one (no priority picked)
Problem two High priority
Problem three   Low priority

My $prob[] would be:My $level[] would be:

$prob[0]: Problem one   $level[0]:  High
$prob[1]: Problem two   $level[1]:  Low
$prob[2]: Problem three

So as you can see my second problem does not correctly correspond to the
correct priority.  The first (or all) element(s) in the level array may
be null.

I have read up on and tried some associative arrays but no luck in
utilizing them within a form; been trying all sorts of testing, books,
web tuts, etc. but still come up with the same problem.  

Also in case anyone were to suggest sessions, my supervisor is adamently
opposed to using them on this site, not sure why, not even sure if that
would make my life easier or not since I've never used them.

Any comments (good, bad, indifferent) here would be most appreciated. 
Any suggestions as to other ways of doing this also appreciated.

Many thanks 

Mignon


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php