Shahmat,

I have the following table in my MySQL db:

mysql> describe news;
+-----------+----------------------+------+-----+---------+----------------+
| Field     | Type                 | Null | Key | Default | Extra          |
+-----------+----------------------+------+-----+---------+----------------+
| newsID    | smallint(5) unsigned |      | PRI | NULL    | auto_increment |
| type      | char(1)              | YES  |     | NULL    |                |
| headline  | varchar(255)         | YES  |     | NULL    |                |
| story     | text                 | YES  |     | NULL    |                |
| startDate | date                 | YES  |     | NULL    |                |
| endDate   | date                 | YES  |     | NULL    |                |
| creator   | smallint(6)          | YES  |     | NULL    |                |
+-----------+----------------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)

The following code in PHP:
$query = "select distinct extract(YEAR_MONTH from startDate) as shahmat from
news";
$result = mysql_query( $query );

while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
        echo $row["shahmat"];
}

Produces the following result in the browser:
200303

I should also mention that there are 8 rows of data in my table, all with
the same date and the date is stored in the 2003-03-06 format.

So, I guess my first question back to you would be: How is your visitdate
column set up in your table? Is it DATE format?

Did you say the query works properly from the MySQL command line? If so,
maybe your db connection isn't set up properly (grasping at straws). Sorry I
can't be of more help, but I was able to get it to work just fine using the
same basic syntax you used.

HTH,
Rich


> -----Original Message-----
> From: Shahmat Dahlan [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, October 21, 2003 12:42 AM
> To: php-db
> Subject: [PHP-DB] acquiring value from a sql statement which 
> contains an
> alias
> 
> 
> I have a question,
> I have this SQL statement,
> $sql_stmt = "SELECT DISTINCT EXTRACT(YEAR_MONTH FROM visitdate) AS 
> availYearMonth FROM visitedurl;";
> 
> $result = mysql_query ($sql_stmt);
> while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
>     echo $row["availYearMonth"];
> }
> 
> By right the value that I should be getting is "200310" via the Mysql 
> command line client. But with PHP all I got was the value of "1".
> 
> Would appreciate if anyone can nudge me in the right directory.
> 
> Thanks in advance and would appreciate it.
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

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

Reply via email to