Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date from MySQL returns NULL

Tags:

date

null

mysql

This is my table structure:

Datum (Timestamp)     |IP   |X (times visited)
2012-09-08 14:09:44    *      10
2012-09-08 13:20:01    *      34

I'm getting the data from mySQL using:

$Darray=array();
$q="SELECT FROM Datum from ips ORDER BY X DESC";
$rs=mysql_query($q) or die(mysql_error());
while($rd=mysql_fetch_object($rs))
{
$Darray[]=$rd->X;
}

But when i try

var_dump($Darray[1]);

I get NULL.

I also tried using

SELECT FROM_UNIXTIME(Datum) from ips ORDER BY X DESC

But it doesn't change anything

like image 896
Niek Avatar asked Jul 04 '26 00:07

Niek


1 Answers

You are putting the X column into your array instead of Datum, and it is likely null because your SQL is wrong.

// Create array to hold date values
$date_array = array();

// Get all dates from ips table ordered by X column
$q = "SELECT `Datum` FROM `ips` ORDER BY `X` DESC";

// Query mysql
$rs = mysql_query($q) or die(mysql_error());

// Loop through results as PHP objects
while( $rd = mysql_fetch_object($rs) ) {
    // put the Datum value into array
    $date_array[] = $rd->Datum;
}

// Dump the contents of the $date_array
var_dump($date_array);
like image 156
doublesharp Avatar answered Jul 09 '26 06:07

doublesharp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!