私のケースは基本的にはこれです:itemsforsale、itemsforrent、wanteditemsという3つのテーブルがあります。これらのテーブルのそれぞれは同じ数の列と同じ名前を持ちます。 USERIDが私の選択したIDと等しいこれらの3つのテーブルからすべてのデータを選択して、それらを行として出力したいとします。動いていない。ここに私のコードは次のとおりです。複数のテーブルからデータを選択して印刷する
$sql = "SELECT sale.propertype as propertytype,sale.description as description,sale.price as price,sale.telefone1 as telefone1,sale.telefone2 as telefone2,sale.userid as userid,sale.propertyid as propertyid,sale.area as area,sale.dateposted as dateposted,sale.datebumped as datebumped,sale.images as images,sale.hiddentype as hiddentype,sale.pricetype as pricetype,sale.size as size FROM itemsforsale sale WHERE userid = '1'
UNION SELECT rent.propertype as propertytype,rent.description as description,rent.price as price,rent.telefone1 as telefone1,rent.telefone2 as telefone2,rent.userid as userid,rent.propertyid as propertyid,rent.area as area,rent.dateposted as dateposted,rent.datebumped as datebumped,rent.images as images,rent.hiddentype as hiddentype,rent.pricetype as pricetype,rent.size as size FROM itemsforrent rent WHERE userid = '1'
UNION select wanted.propertype as propertytype,wanted.description as description,wanted.price as price,wanted.telefone1 as telefone1,wanted.telefone2 as telefone2,wanted.userid as userid,wanted.propertyid as propertyid,wanted.area as area,wanted.dateposted as dateposted,wanted.datebumped as datebumped,wanted.images as images,wanted.hiddentype as hiddentype,wanted.pricetype as pricetype,wanted.size as size from itemswanted wanted WHERE userid = '1'";
$result = mysqli_query($mysqli, $sql);
エラー: 警告:mysqli_fetch_array()私はそれが正常に動作しない場合はブール値がライン290
にblahblahで与えられ、パラメータ1がmysqli_resultことを期待しています。どんな助け?
私はテーブル内のすべてを選択します。それはどうですか? – Ali
すべてのSELECT文に対してコンマ区切りの列リストを指定できます。 –
なので、*の代わりにすべての列を選択する必要がありますか? – Ali