Reputation: 1030
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
Upvotes: 3
Views: 108
Reputation: 27599
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);
Upvotes: 2
Reputation: 50563
Your sql is wrong you have two FROM clauses (FROM Datum from ips
):
$q="SELECT FROM Datum from ips ORDER BY X DESC";
Upvotes: 1