如何结合到php(sql)

时间:2017-04-27 21:21:50

标签: php mysql sql

我需要结合这两个代码,更可能是sql。我坐了几个小时就无法得到它。

<?php
$mysqli2 = new mysqli("Edudb", "mct", "QwSkepticx97!");
$mysqli2->select_db("maturita");
$ask2 = $mysqli2->query("SELECT * FROM gallery");
if(mysqli_num_rows($ask2)>0)
{   
while ($row2=mysqli_fetch_object($ask2)) 
{   
echo "<a href='show-gall.php?gallery=$row2->gall_id'>$row2->name<br></a</span>";
}
}       
?>

和这一个

<?php
$conn = mysqli_connect("Edudb", "mct", "QwSkepticx97!", "maturita");
$sql="SELECT g.name, i.img_thumb FROM gallery g JOIN images i ON g.gall_id = i.gall_id GROUP BY g.gall_id ";
$query=mysqli_query($conn, $sql);
if(mysqli_num_rows($query)>0)
{   
while ($row=mysqli_fetch_object($query)) 
{
    echo "<div class='view'>";
    echo "<a href='show-gall.php?gallery=$row->gall_id'><img src='$row->img_thumb' alt=''></a>";
    echo "<br/>";   
    echo "<a href='show-gall.php?gallery=$row->gall_id'>$row->name</a>";
    echo "<br/>";
    echo "</div>";
 }
}   
?>

我会感谢任何建议

1 个答案:

答案 0 :(得分:-1)

试试这个

include('here put the name of one file of two ');

然后将此声明放在另一个声明中。 现在,包含include()语句的另一个文件显示了第二个文件中的所有内容。