RE: [PHP] how did this become an array?

2002-04-02 Thread Rick Emery

  What I don't understand is how did $result_row become $result_row[0] and
  $result_row[1]?

mysql_fetch_row() returns an array structure

  Also what does it mean to select max(thread) as thread, max(mesid) as
  mesgid?  I have never used this as command before.

max(x) returns the highest value for all records in that particular field
The AS clause renames the resulting field.  For instance, in this case,
max(thread) returns as a field named thread.  So you would access like:

$result_row = mysql_fetch_array($result);
$mythread = $result_row['thread'];

I suggest you experiment in the mysql command line to see the various
results.

-Original Message-
From: The PHP newbie [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 02, 2002 8:10 AM
To: [EMAIL PROTECTED]
Subject: [PHP] how did this become an array?



Hi,

I am trying to figure out a part of the PHP code which belongs to one of
the files that is responsible for operating a discussion group.

I was examining some of a part of the code which produces the total number
of messages and displays the subject of the message.

I encountered a part that looks like this:

mysql_select_db(discussionboard, $db)
   or die(Couldnot select database);

$sql = select max(thread) as thread, max(mesgid) as mesgid from
discussionboard;

$result = mysql_query($sql)
or die(Query failed);

$numrows = mysql_num_rows($result);

$result_row = mysql_fetch_row($result);
echocenterbNo of topics: $result_row[0]br
No of total messages: $result_row[1]/b


What I don't understand is how did $result_row become $result_row[0] and
$result_row[1]?

Also what does it mean to select max(thread) as thread, max(mesid) as
mesgid?

I have never used this as command before.

Thanks for any insight.

Peter



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

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




Re: [PHP] how did this become an array?

2002-04-02 Thread RIVES Sergio

Hi,

I am also a newbie in PHP, but your question is more a MySQL question I
believe... :
$sql = select max(thread) as thread, max(mesgid) as mesgid from
discussionboard;
This MySQL request gives you two informations : the maximum of the values of
the two fields (thread and mesgid) of the table named discussionboard : these
values are then put with $result_row = mysql_fetch_row($result) inside a row
of two values : $result_row[0] and $result_row[1].
I hope that helps you

P.S.: see the site www.mysql.com for more or clearer explanations and also of
course www.php.net

SR


The PHP newbie a écrit :

 Hi,

 I am trying to figure out a part of the PHP code which belongs to one of
 the files that is responsible for operating a discussion group.

 I was examining some of a part of the code which produces the total number
 of messages and displays the subject of the message.

 I encountered a part that looks like this:

 mysql_select_db(discussionboard, $db)
or die(Couldnot select database);

 $sql = select max(thread) as thread, max(mesgid) as mesgid from
 discussionboard;

 $result = mysql_query($sql)
 or die(Query failed);

 $numrows = mysql_num_rows($result);

 $result_row = mysql_fetch_row($result);
 echocenterbNo of topics: $result_row[0]br
 No of total messages: $result_row[1]/b

 What I don't understand is how did $result_row become $result_row[0] and
 $result_row[1]?

 Also what does it mean to select max(thread) as thread, max(mesid) as
 mesgid?

 I have never used this as command before.

 Thanks for any insight.

 Peter

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