我正在使用此代码。
include('db_con.php');
$query="SELECT retailerData.poster,retailerData.banners,retailerData.tradeLetters,retailerData.stickers ,retailerData.buntings, retailerData.visitDate FROM retailerData INNER JOIN retailer ON retailer.retailerID=retailerData.retailerID WHERE retailer.retailerID IN( SELECT retailer.retailerID FROM retailer INNER JOIN office ON office.officeID= retailer.officeID WHERE office.officeID IN( SELECT officeID FROM office WHERE parentOfficeID IN (
SELECT officeID FROM office WHERE parentOfficeID IN (SELECT officeID FROM office WHERE officeName='$var')
) ) )";
$result=mysqli_query($connect,$query) or die ('Query failed');
if(mysqli_num_rows($result) != 0)
{
$data1y= array();
$data2y= array();
$data3y= array();
$data4y= array();
$data5y= array();
$data6y= array();
while ($row2 = mysqli_fetch_array($result))
{
$data1y[]=$row2['poster'];
$data2y[]=$row2['banners'];
$data3y[]=$row2['tradeLetters'];
$data4y[]=$row2['stickers'];
$data5y[]=$row2['buntings'];
$data6y[]=$row2['visitDate'];
}
}
foreach($data1y as $value)
echo" $value ";
查询工作正常,但$ row2数组中的数据未存储在其他数组中。 foreach声明没有给出任何输出。
答案 0 :(得分:0)
我无法使用您的代码,因为它似乎使用了旧的已弃用的 mysql 函数。
试试这个:
$connection = new mysqli("ip.add.res.s", "user", "password", "dbname");
$sql = "SELECT ....";
if (!$result = $connection->query($sql)) die ("Query failed");
if ($result->num_rows > 0) {
while ($row2 = $result->fetch_assoc()) {
// do your stuff here
}
}