Re: [PHP] What wrong am I doing now?

[email protected] (Matijn Woudt)
Newsgroups php.general
Message-ID <CAC_gtuN_31_-6rbdzdQN7VwOpzGNRQEo-yQOZYGLeL1b1LczNg@mail.gmail.com>
On Wed, Jul 24, 2013 at 2:19 PM, Karl-Arne Gjersøyen <[email protected]>wrote:

> mysql> SELECT DATE_FORMAT(dato, '%e-%c-%Y') FROM transportdokument WHERE
> dato >= '2013-07-20' AND dato <= '2013-07-24' GROUP BY dato DESC;
> +-------------------------------+
> | DATE_FORMAT(dato, '%e-%c-%Y') |
> +-------------------------------+
> | 24-7-2013                     |
> | 23-7-2013                     |
> +-------------------------------+
> 2 rows in set (0.00 sec)
>
> mysql>
>
>
> // My PHP code looks like this.
> // -----------------------------------------
> $sql = "SELECT DATE_FORMAT(dato, '%e-%c-%Y') FROM transportdokument WHERE
> dato >= '2013-07-20' AND dato <= '2013-07-24' GROUP BY dato DESC";
> $resultat = mysql_query($sql, $tilkobling) or die(mysql_error());
>
> while($rad = mysql_fetch_array($resultat)){
> $dato = $rad['dato'];
>

$rad['dato'] probably doesn't exist because you used DATE_FORMAT.
Either use $rad[0], or use the following SQL:

$sql = "SELECT DATE_FORMAT(dato, '%e-%c-%Y') AS dato FROM transportdokument
WHERE dato >= '2013-07-20' AND dato <= '2013-07-24' GROUP BY dato DESC";

Regards,

Matijn
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.