php-general Digest 1 May 2005 16:43:58 -0000 Issue 3429

Topics (messages 214278 through 214282):

Re: Splitting Vars from MySQL in PHP
        214278 by: Richard Lynch
        214279 by: Rasmus Lerdorf

Re: Extending Element class in a dom tree?
        214280 by: Erik Franz�n

users online
        214281 by: Anasta

Starting a big project
        214282 by: Danny Brow

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 ---
On Fri, April 29, 2005 4:36 pm, Philip Olson said:
>> > I remember in Perl I used to extract vars from a single fetchrow by
>> adding
>> > each var name to the beginning (like this). Only this ain'ta workin
>> :)...
>> > Anyone know the right syntax to do this?
>> >
>> > ($var1, $var2, $var3)= mysql_fetch_array($result, MYSQL_ASSOC)
>>
>>
>> list($var1, $var2, $var3) = mysql_fetch_array($result, MYSQL_ASSOC);
>> http://us4.php.net/manual/en/function.list.php
>
> But remember that list() only works with numerical
> arrays so use MYSQL_NUM (or array_values()) in the
> above. For associative, extract() can be useful.

I dunno what the documentation is trying to say when it says "list only
works with numerical indices" but it's patently false:

php -a
<?php
  $foo = array('a'=>'apple', 'b'=>'banana', 'c'=>'coconut');
  while (list($k, $v) = each($foo)){
    echo "$k: $v\n";
  }
?>
Content-type: text/html
X-Powered-By: PHP/4.3.11

a: apple
b: banana
c: coconut

It has worked just fine with alpha indices since PHP 3.0rc2, at a minimum,
cuz I've been doing it that long.

I dunno who was smoking what that day they typed the documentation :-)

I'm pretty sure it's not an "undocumented feature" that it works.

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message --- Richard Lynch wrote:
On Fri, April 29, 2005 4:36 pm, Philip Olson said:

I remember in Perl I used to extract vars from a single fetchrow by

adding

each var name to the beginning (like this). Only this ain'ta workin

:)...

Anyone know the right syntax to do this?

($var1, $var2, $var3)= mysql_fetch_array($result, MYSQL_ASSOC)


list($var1, $var2, $var3) = mysql_fetch_array($result, MYSQL_ASSOC);
http://us4.php.net/manual/en/function.list.php

But remember that list() only works with numerical arrays so use MYSQL_NUM (or array_values()) in the above. For associative, extract() can be useful.


I dunno what the documentation is trying to say when it says "list only
works with numerical indices" but it's patently false:

php -a
<?php
  $foo = array('a'=>'apple', 'b'=>'banana', 'c'=>'coconut');
  while (list($k, $v) = each($foo)){
    echo "$k: $v\n";
  }
?>
Content-type: text/html
X-Powered-By: PHP/4.3.11

a: apple
b: banana
c: coconut

It has worked just fine with alpha indices since PHP 3.0rc2, at a minimum,
cuz I've been doing it that long.

I dunno who was smoking what that day they typed the documentation :-)

I'm pretty sure it's not an "undocumented feature" that it works.

Richard, this is what the docs are talking about:

  list($a,$b,$c,$d) = array('a','b','c','d');
  echo $a,$b,$c,$d;

vs.

  list($a,$b,$c,$d) = array('a'=>'a','b'=>'b','c'=>'c','d'=>'d');
  echo $a,$b,$c,$d;

In your case you are calling each() which itself returns a numerically indexed array.

-Rasmus
--- End Message ---
--- Begin Message ---
Christian Stocker wrote:

Does not work, will never work, just forget about it ;)


Ok, that was not the really right answer ;) Of course it does work.
You can even do stuff on that element, if you use the variable, resp.
reference ($oMyElement) for doing this.

What doesn't work (and I  referred to that) is getting this object
back from the DomDocument, so for example:
$oDom->documentElement will give you the DomElement back and not your
new MyElement.

Hope it's a little bit clearer now
chregu

chregu


You mean that dom methods for retrieving Elements will only return objects with the object methods defined in the DomElement class?


Is there any way to extend Elements in the tree with own methods? Or is the dom structurue only used to handle defined methods?

The method DomDocument::CreateElement() only returns instances of DomElement so maybee the Dom structure is not meant to be extended regarding elements?

/Erik
--- End Message ---
--- Begin Message ---
Hi, is this possible--
I need a user (already logged in) to click on a button and his username
shown in a text box next to it.
 This is for a chat and they need to be seated similar to poker game where
they sit-in/sit out.

Any help apreciated !

--- End Message ---
--- Begin Message ---
I'm about to start writing a big web app (mostly in PHP). But I'm not
sure if I should layout the DB first then write the app, or should I
just start writing the app and add stuff to the DB as I need it. How do
you guys go about it?

Thanks,
Dan.

--- End Message ---

Reply via email to