-1
<?php    
$dbhost = 'localhost'; 
$dbuser = 'root'; 
$dbpass = ''; 
$dbname = 'moviefone';   
$con = mysql_connect($dbhost, $dbuser, $dbpass); 
mysql_select_db($dbname, $con); 
// Check connection 
if (mysqli_connect_errno()) { 
echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
}    
$data = mysql_query(
"
SELECT * 
  FROM new_hindi 
  JOIN new_eng 
 ORDER 
    BY id DESC 
 LIMIT 4
 ") or die(mysql_error());    

 $info=array();    

 while ($row =mysql_fetch_array($data)){
    $info[]=$row;    }    

?>

我的问题是它只循环第一个表中的最后一个数据,而第二个表中它循环最后四个条目。我想要的是第一个表也循环最后四个条目。

4

2 回答 2

0

虽然您使用的库已被弃用,并且不应该用于新项目(http://us3.php.net/function.mysql-connect),但您的问题在于您的 join 语句。您需要指示 SQL如何连接表。下面是一个通用示例:

SELECT `field1` FROM `table1` INNER JOIN `table2` ON 
`table1`.`id` = `table2`.`table1_id` WHERE etc...

干杯

于 2013-11-11T18:41:35.943 回答
0

也许你在追求 UNION ......

$query = "
SELECT * 
  FROM new_hindi 
 UNION 
SELECT *
  FROM new_eng 
 ORDER 
    BY id DESC 
 LIMIT 4;
 ";

$result = mysqli_query($db,$query) or die(mysqli_error());    

$info=array();    

 while ($row =mysql_fetch_array($result)){
 $info[]=$row;    
} 
于 2013-11-11T18:54:49.743 回答