我需要用2個表格工作,我嘗試了內部連接,4個結果的位置,它只是顯示了兩個表格的結果,我正在粘貼這兩個查詢,請看它並幫助我,我會感謝你們所有人。PHP循環查詢不起作用
<?
$query5 = "SELECT * FROM escorts_touring order by es_tou_id";
$result5 = mysql_query($query5);
while($row5 = @mysql_fetch_array ($result5, MYSQL_ASSOC))
{
$es_touring_city = $row5['es_touring_city'];
}
?>
<?php
echo $sql="SELECT e.es_id, e.es_sex, e.service_type,
e.working_name, t.es_tou_id, t.es_id,
t.es_touring_city, t.es_touring_start_date,
t.es_touring_end_date
FROM escorts AS e
INNER JOIN escorts_touring AS t
ON e.es_id = t.es_id
where es_touring_city = '$es_touring_city'";
$result=mysql_query($sql);
$rowcount=mysql_num_rows($result);
$counter=0;
$count=0;
while($row = @mysql_fetch_array ($result, MYSQL_ASSOC))
{
if($counter++%4==0)print"</div><div class=\"row\"></div>";
$es_sex =$row['es_sex'];
$service_type=$row['service_type'];
$working_name=$row['working_name'];
$es_id=$row['es_id'];
$es_tou_id = $row['es_tou_id'];
$es_touring_city = $row['es_touring_city'];
$es_touring_start_date = $row['es_touring_start_date'];
$es_touring_end_date =$row['es_touring_end_date'];
$newstartDate = date("dS F, Y", strtotime($es_touring_start_date));
$newendDate = date("dS F, Y", strtotime($es_touring_end_date));
$query = "SELECT * FROM escorts_image where es_id = $es_id";
$result_image = @mysql_query ($query);
$row_image = @mysql_fetch_array ($result_image, MYSQL_ASSOC);
$image = $row_image['image'];
$dest="uploads";
?>
當我打印/回波
$es_touring_city = $row5['es_touring_city'];
其示出圖4的結果。
但是當我在第二個查詢中使用$ es_touring_city時,它只顯示2個結果與圖像。
如果我不是很清楚說話。
謝謝,
每次你在新的使用[了'mysql_'(http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) 數據庫擴展代碼 ** [小貓被勒死在世界的某個地方](http://2.bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)**它被棄用,並已多年,並在PHP7中永遠消失。 如果您只是學習PHP,請花些精力學習'PDO'或'mysqli'數據庫擴展。 [從這裏開始](http://php.net/manual/en/book.pdo.php) – RiggsFolly
你不應該使用這樣的嵌套查詢。他們非常低效。您應該重寫爲單個「連接」查詢。你已經加入了第二個,所以擴展它們以覆蓋父/子查詢。 –
不要使用'@'錯誤消音器。如果你有錯誤,先顯示然後第二個修復他們 – RiggsFolly