Re: [PHP] Assign multiple variables from mysql_fetch_row() call

2001-09-05 Thread Ryan Fischer

  You wrote:
   ($var1, $var2) is magic.  I hate magic.
 
  It's not magic.  It's just simpler.
 
   What do you look up in the Perl
   manual when you hit syntax like that?
 
  http://www.perldoc.com/perl5.6/pod/perldata.html

 I said what not where.  I still maintain that if you don't know
where
 to look, () is not an easy thing to search for.

Sure it is.  Lists or list context.  () is not that hard to determine
what it means.  At least, not nearly as hard as you make it out to be
for any moderately-experienced programmer.

--
 -Ryan :: ICQ - 595003 :: GigaBoard - http://www.gigaboard.net/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Assign multiple variables from mysql_fetch_row() call

2001-09-05 Thread Sheridan Saint-Michel

- Original Message -
From: Ryan Fischer [EMAIL PROTECTED]
To: Mark Maggelet [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Wednesday, September 05, 2001 1:35 PM
Subject: Re: [PHP] Assign multiple variables from mysql_fetch_row() call


 You wrote:
  I use list context a lot in PHP and Perl, and I prefer Perl's way of
  doing it *because* it allows you to be as verbose or terse as you
  like.
  PHP, unfortunately, doesn't give you that freedom.
 
  Hmm... the freedom to write unreadable, unmaintainable code, yes this
  is a very important feature.

 Yes, well, that all depends on who's writing it.  I've been writing Perl
 for several years, and believe you me, the code is plenty readable.
 And, it's much more concise than anything written in PHP.  That freedom
 is what's so appealing about Perl.  But of course, I'm on a PHP list
 (because I like both), so the people who will agree with me are few and
 far between.

 One can write unreadable code in PHP or Perl.  It all depends on what
 you know about the language and how well you are able to use it.
 Keywords make no real difference, because when I see ($foo, $bar), I
 know it's a list.  I don't need a list() operator to know that.  ;)

 --
  -Ryan :: ICQ - 595003 :: GigaBoard - http://www.gigaboard.net/

Which is why you see spoofs like this one
http://bbspot.com/News/2001/03/perl_test.html

I'm sorry, I have heard the arguments that PERL can be extremely readable
if written properly.  The problem with this from the standpoint of someone
trying to learn the language is that many (if not most) people who program
in
PERL don't take the time to write readable code.  This makes both
maintaining
and learning from PERL programs more difficult.  I think that they would
even
admit on a PERL list that PERL does have a higher learning curve than PHP.

Sheridan


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Assign multiple variables from mysql_fetch_row() call

2001-09-05 Thread Mark Maggelet

On Wed, 5 Sep 2001 14:36:59 -0400, Ryan Fischer ([EMAIL PROTECTED])
wrote:
  You wrote:
   ($var1, $var2) is magic.  I hate magic.
 
  It's not magic.  It's just simpler.
 
   What do you look up in the Perl
   manual when you hit syntax like that?
 
  http://www.perldoc.com/perl5.6/pod/perldata.html

 I said what not where.  I still maintain that if you don't
know
where
 to look, () is not an easy thing to search for.

Sure it is.  Lists or list context.  () is not that hard to
determine
what it means.  At least, not nearly as hard as you make it out to
be for any moderately-experienced programmer.

So it's easy to look it up is if you already know what it does? I
think the majority of people looking it up would be
not-so-experienced programmers :)



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Assign multiple variables from mysql_fetch_row() call

2001-09-05 Thread Ryan Fischer

You wrote:
 Sure it is.  Lists or list context.  () is not that hard to
 determine
 what it means.  At least, not nearly as hard as you make it out to
 be for any moderately-experienced programmer.

 So it's easy to look it up is if you already know what it does? I
 think the majority of people looking it up would be
 not-so-experienced programmers :)

Yes, but an inexperienced programmer wouldn't know where to look for
list, either.  When you see ($foo, $bar), you know two or more items are
a list.  What is a list?  Two or more items.  What do you have there?
Two or more items.  Rather simple and intuitive to me.  *shrug*

The way you learn to problem shouldn't be looking something up to find
out what it does, but rather learning what everything does, then
applying it by doing the programming afterwards.  This sort of backwards
thinking is what causes problems in the first place.  :\

--
 -Ryan :: ICQ - 595003 :: GigaBoard - http://www.gigaboard.net/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Assign multiple variables from mysql_fetch_row() call

2001-09-05 Thread Mark Maggelet

On Wed, 5 Sep 2001 17:13:59 -0400, Ryan Fischer ([EMAIL PROTECTED])
wrote:
You wrote:
 Sure it is.  Lists or list context.  () is not that hard to
 determine
 what it means.  At least, not nearly as hard as you make it out
to
 be for any moderately-experienced programmer.

 So it's easy to look it up is if you already know what it does? I
 think the majority of people looking it up would be
 not-so-experienced programmers :)

Yes, but an inexperienced programmer wouldn't know where to look for
list, either.  When you see ($foo, $bar), you know two or more items
are
a list.  What is a list?  Two or more items.  What do you have
there?
Two or more items.  Rather simple and intuitive to me.  *shrug*

well, not being an experienced perl programmer I look at that and
have to wonder if it's some weird function or a language construct,
and either way I have no way of looking it up. with list() I know
it's a function and I have a page to flip to in the documentation or
in the back of some book.

The way you learn to problem shouldn't be looking something up to
find out what it does, but rather learning what everything does,
then
applying it by doing the programming afterwards.  This sort of
backwards
thinking is what causes problems in the first place.  :\

so newbies should have to memorize every function before being
allowed to start writing code? It doesn't work that way. That's like
trying to learn chinese by reading a chinese dictionary. Humans learn
the conversational stuff first (hello world, where is the bathroom)
and progress to the more obscure stuff. Php *is* newbie-friendly and
that's a good thing.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Assign multiple variables from mysql_fetch_row() call

2001-09-05 Thread Rasmus Lerdorf

 You wrote:
  Sure it is.  Lists or list context.  () is not that hard to
  determine
  what it means.  At least, not nearly as hard as you make it out to
  be for any moderately-experienced programmer.
 
  So it's easy to look it up is if you already know what it does? I
  think the majority of people looking it up would be
  not-so-experienced programmers :)

 Yes, but an inexperienced programmer wouldn't know where to look for
 list, either.  When you see ($foo, $bar), you know two or more items are
 a list.  What is a list?  Two or more items.  What do you have there?
 Two or more items.  Rather simple and intuitive to me.  *shrug*

 The way you learn to problem shouldn't be looking something up to find
 out what it does, but rather learning what everything does, then
 applying it by doing the programming afterwards.  This sort of backwards
 thinking is what causes problems in the first place.  :\

A rather pointless thread...  But that last phrase is pure gibberish to
me.  If I see foo($blah,$blah) in some code, I'll do a quick grep to see
if foo() is a locally defined function and if it isn't check if it is a
built-in function by checking the documentation.  But perhaps I am a weird
and backwards sort of guy.

-Rasmus


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Assign multiple variables from mysql_fetch_row() call

2001-09-05 Thread Ryan Fischer

 Which is why you see spoofs like this one
 http://bbspot.com/News/2001/03/perl_test.html

The Perl code in that spoof isn't even valid.  ;)

And besides, the fact that you can write Perl code that looks like that
and still functions is more of a feature than anything.  Code that is
written like that is not meant to be readable.  It's meant to serve a
function, and usually, it's written by one person, and read only by that
person.

Hehe... and to think this whole line of discussion started because
someone advocates list() over () when the latter, IMO, is better because
the former is redundant.  That's what it comes down to, really.  *shrug*

 I'm sorry, I have heard the arguments that PERL can be extremely
readable
 if written properly.  The problem with this from the standpoint of
someone
 trying to learn the language is that many (if not most) people who
program
 in
 PERL don't take the time to write readable code.  This makes both
 maintaining
 and learning from PERL programs more difficult.  I think that they
would
 even
 admit on a PERL list that PERL does have a higher learning curve than
PHP.

The same can be said for PHP.  Some people don't take the time to write
readable code, no matter what the language.  Because of this
universality, that makes it a rather moot point.

--
 -Ryan :: ICQ - 595003 :: GigaBoard - http://www.gigaboard.net/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Assign multiple variables from mysql_fetch_row() call

2001-09-05 Thread Rasmus Lerdorf

 Hehe... and to think this whole line of discussion started because
 someone advocates list() over () when the latter, IMO, is better because
 the former is redundant.  That's what it comes down to, really.  *shrug*

Most syntax is redundant.

($var1, $var2) = foo();

might as well be written as:

var1,var2=foo

No point having the brackets there.  The spaces are also redundant of
course.  And so are the dollar signs.

You could continue along these lines until you determine that all
scripting languages are redundant and you might as well code directly in C
until you discover C is redundant as well and go straight to assembly.

Scripting languages exist exactly because they are higher-level (redundant
if you will) layers that present more human-friendly interfaces to the
underlying complexities.  Removing all redundancy in a scripting language
and turning it into a series of 1 or 2 character mneumonics almost
completely eliminates the whole reason for using a scripting language.
Once you learn this set of meaningless mneumonics you can get things done
a bit quicker than someone using a more verbose language.

However, consider why computers don't ship with stenograph-style
keyboards.  An experienced stenographer can type circles around any
regular typist, but the learning curve for becoming an experienced
stenographer is rather steep.  It makes more sense to ship computers with
keyboards that don't require such a learning curve.  Just like it makes
sense to keep the amount of magic meaningless mneumonics to a minimum in a
scripting language.

-Rasmus


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Assign multiple variables from mysql_fetch_row() call

2001-09-04 Thread Rasmus Lerdorf

 In perl I can say something like:

($var1, $var2) = $sqh-fetchrow_array()


 to assign column values to more than one variable at a time.  So I
 tried similar syntax with PHP:


 ($var1, $var2) = mysql_fetch_row($sqh);


 but could not seem to work it out.

 I know you can do this with a temporary array, and then take values
 out of the array.  But it would be nice to omit the temporary array.

 Is it possible?

($var1, $var2) is magic.  I hate magic.  What do you look up in the Perl
manual when you hit syntax like that?  In PHP the equivalent syntax is:

list($var1, $var2) = ...

It does exactly the same thing, and it is legible.  Anybody can pop over
to http://php.net/list and get an explanation of what the code does if
they run across it.

-Rasmus


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Assign multiple variables from mysql_fetch_row() call

2001-09-04 Thread Alfredeen, Johan

You can use a while loop. Ie: (where $row is the result of a sql query)

if ($row = mysql_fetch_array($result)) {
do  {
$var1 = $row[column1];
$var2 = $row[column2];
$var2 = $row[column3];
} while ($row = mysql_fetch_array($result));
}

Johan
Which World? PongWorld
www.pongworld.com


-Original Message-
From: Egan [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, September 04, 2001 3:30 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Assign multiple variables from mysql_fetch_row() call


In perl I can say something like:

   ($var1, $var2) = $sqh-fetchrow_array()


to assign column values to more than one variable at a time.  So I
tried similar syntax with PHP:


($var1, $var2) = mysql_fetch_row($sqh);


but could not seem to work it out.

I know you can do this with a temporary array, and then take values
out of the array.  But it would be nice to omit the temporary array.

Is it possible?


Egan




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Assign multiple variables from mysql_fetch_row() call

2001-09-04 Thread Ryan Fischer

You wrote:
 ($var1, $var2) is magic.  I hate magic.

It's not magic.  It's just simpler.

 What do you look up in the Perl
 manual when you hit syntax like that?

http://www.perldoc.com/perl5.6/pod/perldata.html

 In PHP the equivalent syntax is:

 list($var1, $var2) = ...

Which is longer, and requires you to learn a keyword that you don't need
to learn in Perl.

 It does exactly the same thing, and it is legible.  Anybody can pop
over
 to http://php.net/list and get an explanation of what the code does if
 they run across it.

I use list context a lot in PHP and Perl, and I prefer Perl's way of
doing it *because* it allows you to be as verbose or terse as you like.
PHP, unfortunately, doesn't give you that freedom.

--
 -Ryan :: ICQ - 595003 :: GigaBoard - http://www.gigaboard.net/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Assign multiple variables from mysql_fetch_row() call

2001-09-04 Thread Rasmus Lerdorf

 You wrote:
  ($var1, $var2) is magic.  I hate magic.

 It's not magic.  It's just simpler.

  What do you look up in the Perl
  manual when you hit syntax like that?

 http://www.perldoc.com/perl5.6/pod/perldata.html

I said what not where.  I still maintain that if you don't know where
to look, () is not an easy thing to search for.

-Rasmus


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Assign multiple variables from mysql_fetch_row() call

2001-09-04 Thread Mark Maggelet


I use list context a lot in PHP and Perl, and I prefer Perl's way of
doing it *because* it allows you to be as verbose or terse as you
like.
PHP, unfortunately, doesn't give you that freedom.

Hmm... the freedom to write unreadable, unmaintainable code, yes this
is a very important feature.

That works great if you're a team of one and you're the only one who
will ever maintain your code. For people who live in a society it's a
nightmare :) There's a huge thread on slashdot right now on 'Software
Aesthetics'.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Assign multiple variables from mysql_fetch_row() call

2001-09-04 Thread Egan

On Tue, 4 Sep 2001 14:29:42 -0700 (PDT), Rasmus Lerdorf
[EMAIL PROTECTED] wrote:

 In perl I can say something like:

($var1, $var2) = $sqh-fetchrow_array()

($var1, $var2) is magic.  I hate magic.  What do you look up in the Perl
manual when you hit syntax like that?  In PHP the equivalent syntax is:

list($var1, $var2) = ...

It does exactly the same thing, and it is legible.


Sorry, I didn't mean to start a flame war.

I only wanted to know if there was a simple way of doing it, without
using a temporary array.  The only reason I mentioned perl is because
I did not know any other way to frame the question.

Your suggestion looks like just what I need, thanks!


Egan



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]