Discussion:
What wrong am I doing now?
Sebastian Krebs
2013-07-24 12:26:26 UTC
Permalink
Hi,

Just want to mention: ext/mysel is deprecated. Use MySQLi, or PDO_MYSQL
instead. :)

Regards,
Sebastian
http://www.php.net/manual/en/datetime.format.php have the solution. Sorry
for asking before I look at php.net!!!
Karl
---------- Forwarded message ----------
Date: 2013/7/24
Subject: What wrong am I doing now?
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'];
var_dump($dato);
I gott NULL,NULL here and believe it is something with my PHP Source that
is wrong when using DATE_FORMAT. As you see above it work in terminal.
I hope this not is off-topic for the list. If so, I am sorry for it and
hope you can give me advice about a good MySQL list for newbie's.
Thanks again for your help!
Karl
--
github.com/KingCrunch
Karl-Arne Gjersøyen
2013-07-24 12:24:09 UTC
Permalink
http://www.php.net/manual/en/datetime.format.php have the solution. Sorry
for asking before I look at php.net!!!

Karl

---------- Forwarded message ----------
From: Karl-Arne Gjersøyen <***@gmail.com>
Date: 2013/7/24
Subject: What wrong am I doing now?
To: PHP Mailinglist <php-***@lists.php.net>


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'];
var_dump($dato);

I gott NULL,NULL here and believe it is something with my PHP Source that
is wrong when using DATE_FORMAT. As you see above it work in terminal.

I hope this not is off-topic for the list. If so, I am sorry for it and
hope you can give me advice about a good MySQL list for newbie's.

Thanks again for your help!

Karl
Karl-Arne Gjersøyen
2013-07-24 12:19:16 UTC
Permalink
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'];
var_dump($dato);

I gott NULL,NULL here and believe it is something with my PHP Source that
is wrong when using DATE_FORMAT. As you see above it work in terminal.

I hope this not is off-topic for the list. If so, I am sorry for it and
hope you can give me advice about a good MySQL list for newbie's.

Thanks again for your help!

Karl
Matijn Woudt
2013-07-24 12:25:00 UTC
Permalink
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
Jim Giner
2013-07-24 12:45:29 UTC
Permalink
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'];
var_dump($dato);
I gott NULL,NULL here and believe it is something with my PHP Source that
is wrong when using DATE_FORMAT. As you see above it work in terminal.
I hope this not is off-topic for the list. If so, I am sorry for it and
hope you can give me advice about a good MySQL list for newbie's.
Thanks again for your help!
Karl
Add a check on the query result to be sure your query actually ran.
$resultat = mysql_query($sql, $tilkobling) or die(mysql_error());
if (!$resultat)
{
echo "Query failed to run - ".mysql_error();
exit();
}
while($rad = mysql_fetch_array($resultat)){
....
...
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Matijn Woudt
2013-07-24 12:54:19 UTC
Permalink
Post by Jim Giner
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'];
var_dump($dato);
I gott NULL,NULL here and believe it is something with my PHP Source that
is wrong when using DATE_FORMAT. As you see above it work in terminal.
I hope this not is off-topic for the list. If so, I am sorry for it and
hope you can give me advice about a good MySQL list for newbie's.
Thanks again for your help!
Karl
Add a check on the query result to be sure your query actually ran.
$resultat = mysql_query($sql, $tilkobling) or die(mysql_error());
if (!$resultat)
{
echo "Query failed to run - ".mysql_error();
exit();
}
while($rad = mysql_fetch_array($resultat)){
....
...
Jim,

He already has that...

- Matijn
Jim Giner
2013-07-24 13:17:47 UTC
Permalink
Post by Matijn Woudt
Jim,
He already has that...
- Matijn
oops
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...