dポイントプレゼントキャンペーン実施中!

いつもお世話になります。思い切ってまたお尋ねします。
環境はPHP4.4.7+MySQL5.0.41です。
mysql> CREATE TABLE bbb(
-> id MEDIUMINT NOT NULL AUTO_INCREMENT,
-> hiduke DATE,
-> apple INT,
-> orange INT,
-> comment VARCHAR(30),
-> PRIMARY KEY (id));  として
----+------------+-------+--------+---------+
| id | hiduke | apple | orange | comment |
+----+------------+-------+--------+---------+
| 1 | 2007-10-01 | 25 | 63 | zansuu |
| 2 | 2007-10-02 | 30 | 134 | hacchu |
| 3 | 2007-10-03 | 28 | 92 | nyuuka |
| 4 | 2007-10-04 | 41 | 151 | uriage |
| 5 | 2007-10-05 | 14 | 4 | zansuu |
+----+------------+-------+--------+---------+
というテーブル[bbb]を作り、フィールド(カラム)のデータを一連に取得したいと思っています(例えばappleの数なら25,30,28・・・・・というように)。

<?php
mysql_connect(localhost,PQR,*****);
mysql_select_db(XYZ);
$sql=mysql_query("select hiduke from bbb");
 //または "select apple from bbb"
mysql_query($sql) or die(mysql_error().$sql."<br>");
$rows=mysql_num_rows($sql);
if($rows == 0){
print "データがありません";
}else{
print($rows["hiduke"]);
print "<p>\n";
}
?>
と実行すると、
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #3' at line 1Resource id #3
というエラーが出ます。いろいろ調べましたが、意味がわかりません。何がいけないのでしょうか?

A 回答 (1件)

> $sql=mysql_query("select hiduke from bbb");


>  //または "select apple from bbb"
> mysql_query($sql) or die(mysql_error().$sql."<br>");

1行目のmysql_queryの結果を$sqlに格納して、
それを使って再びmysql_queryを実行していますが、
正しいのでしょうか?

この回答への補足

ありがとうございます。いろいろ試していますが、うまくいかないです。コンソール上で
mysql> select hiduke from bbb; とすると、データが取得できますが、

<html>
<body>
<?php
mysql_connect(localhost,PQR,*****);
mysql_select_db(XYZ);
$sql=mysql_query("select hiduke from bbb");
mysql_error();
print($sql);
?>
</body>
</html>
としてブラウザから見ると、Resource id #3  と出てしまい、データが取得できません。hidukeを'hiduke'とコンマで囲っても同じです。
どこが悪いのでしょうか? よろしくお願いします。

補足日時:2007/10/20 14:35
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!