php-windows Digest 5 Apr 2004 18:34:23 -0000 Issue 2195

Topics (messages 23362 through 23364):

php newbie, losing variable scope across functions
        23362 by: bry.itnisk.com
        23363 by: DvDmanDT

Re: Update multiple records from a text field
        23364 by: Justin Patrin

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
Hi, I have an application I'm transferring 
to php. Right now I'm in the rough outlining 
of functionality stage. The application has 
a couple of include files:

1. site-defaults.php
2. xml-functions.php

and the application sets some last minute 
variables in the php that includes the other 
documents.
unfortunately when I refer to these 
variables in the included documents they 
don't resolve. So to try and get them to do 
so i did the following in my xml-
functions.php

$smenu = "default";
function getparams(){

$params= "<params><param name='cssType'>";
$params = $params . "Dynamic</param>";
$params = $params . "<param 
name='menuref'>" . 
$smenu . "</param></params>";



return $params;

}

now at this point i would be happy if i 
could 
get the variable to resolve when declared in 
the same file as the function which 
references it. (I can of course get the 
variable values if i put them into a 
function that returns them when asked and 
call that function, but that seems like it 
shouldn't be the solution.) 

please note that the above example's line 
breaking is done by my email program, if i 
declare $smenu in the getparams function it 
resolves fine. 

Also if anyone has any code to handle 
getparams as a dom builder please pass it 
along, as i will have to do that as some 
point to complete the application's 
funcionality. 

--- End Message ---
--- Begin Message ---
Umm..

I think you want the global keyword...

function getparams()
{
global $smenu;
...
}


-- 
// DvDmanDT
MSN: dvdmandt€hotmail.com
Mail: dvdmandt€telia.com
<[EMAIL PROTECTED]> skrev i meddelandet news:[EMAIL PROTECTED]
> Hi, I have an application I'm transferring
> to php. Right now I'm in the rough outlining
> of functionality stage. The application has
> a couple of include files:
>
> 1. site-defaults.php
> 2. xml-functions.php
>
> and the application sets some last minute
> variables in the php that includes the other
> documents.
> unfortunately when I refer to these
> variables in the included documents they
> don't resolve. So to try and get them to do
> so i did the following in my xml-
> functions.php
>
> $smenu = "default";
> function getparams(){
>
> $params= "<params><param name='cssType'>";
> $params = $params . "Dynamic</param>";
> $params = $params . "<param
> name='menuref'>" .
> $smenu . "</param></params>";
>
>
>
> return $params;
>
> }
>
> now at this point i would be happy if i
> could
> get the variable to resolve when declared in
> the same file as the function which
> references it. (I can of course get the
> variable values if i put them into a
> function that returns them when asked and
> call that function, but that seems like it
> shouldn't be the solution.)
>
> please note that the above example's line
> breaking is done by my email program, if i
> declare $smenu in the getparams function it
> resolves fine.
>
> Also if anyone has any code to handle
> getparams as a dom builder please pass it
> along, as i will have to do that as some
> point to complete the application's
> funcionality.

--- End Message ---
--- Begin Message --- Kaizer Boab wrote:

This has still got me stumped.

I tried the following script to update the table but I'm still experiencing
the same result, only one row updates, the rest remain unchanged.

while (list($k, $v) = each($qty))
 {
 $newQty = $v;
 $update = "update cart set qty = $newQty WHERE trackerId = $trackerId AND
albumId = $albumId";
 mysql_query($update);
 }


for($i = 0; $i < sizeof($qty); ++$i) {
$update = 'update cart set qty = '.$qty[$i].' WHERE trackerId = '.$trackerId[$i].' AND albumId = '.$albumId[$i];
mysql_query($update);
}



I then tried changing my form field names on my View Cart page to name="albumId[]" and name="trackerId[]" as well. I could view the results using the array_multisort function with this script:

echo("<table border=\"1\">\n");
for ($i=0; $i < count($trackerId); $i++) {

echo("<tr><td>$qty[$i]</td><td>$albumId[$i]</td><td>$trackerId[$i]</td>\n");
}
echo("</table>\n");

But I am still confused as to how to get the script to update more than one
row.


You need to use what I said in my reply. Change name="qty" to
name="qty[]" or name="qty[some database id]".

--
paperCrane <Justin Patrin>

Just try a print_r to see how it comes out and work from there. ;-)


You'll have an array of values.

--
paperCrane <Justin Patrin>

-- paperCrane <Justin Patrin>

--- End Message ---

Reply via email to