3

これは私のテーブル構造です:

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

以下を使用して、mySQL からデータを取得しています。

$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;
}

しかし、私がしようとすると

var_dump($Darray[1]);

私はNULLを取得します。

私も使ってみました

SELECT FROM_UNIXTIME(Datum) from ips ORDER BY X DESC

でも何も変わらない

4

2 に答える 2

2

Xの代わりに配列に列を入れていDatumますが、SQL が間違っているため、null である可能性があります。

// 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);
于 2012-09-22T14:40:16.137 に答える
1

SQL が間違っています。2 つの FROM 句があります ( FROM Datum from ips):

$q="SELECT FROM Datum from ips ORDER BY X DESC";
于 2012-09-22T14:30:33.557 に答える