Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从两个表中进行选择,并从一个表中仅显示一个项目,从第二个表中显示多个项目?_Php_Mysql - Fatal编程技术网

Php 如何从两个表中进行选择,并从一个表中仅显示一个项目,从第二个表中显示多个项目?

Php 如何从两个表中进行选择,并从一个表中仅显示一个项目,从第二个表中显示多个项目?,php,mysql,Php,Mysql,我有两个表user和Image table,我只想在Image表中选择profile图片,在user表中我可以选择3个字段。我尝试使用内部连接,但我看不到任何图像显示和没有错误。下面是我的密码 <?Php $target = "image_uploads/"; $image_name = (isset($_POST['image_name'])); $query ="select * from tish_user inner join tish_images on tish_user.

我有两个表user和Image table,我只想在Image表中选择profile图片,在user表中我可以选择3个字段。我尝试使用内部连接,但我看不到任何图像显示和没有错误。下面是我的密码

<?Php
$target = "image_uploads/";
$image_name = (isset($_POST['image_name']));
$query ="select * from
 tish_user inner join tish_images
 on tish_user.user_id = tish_images.user_id";
    $result= $con->prepare($query);
    $result->execute();

$table = <<<ENDHTML
<div style ="text-align:center;">
<h2>Client Review Software</h2>
<table id ="heredoc" border ="0" cellpaddinig="2" cellspacing="2" style = "width:100%"  ;
margin-left:auto; margin-right: auto;>
<tr>
<th>Name</th>
<th>Last Name</th>
<th>Ref No</th>
<th>Cell</th>
<th>Picture</th>
</tr>
ENDHTML;

while($row = $result->fetch(PDO::FETCH_ASSOC)){
    $date_created = $row['date_created'];
        $user_id = $row['user_id'];
        $username = $row['username'];

        $image_id = $row['image_id'];

        #this is the Tannery  operator to replace a pic when an id do not have one
$photo = ($row['image_name']== null)? "me.png":$row['image_name'];
#display image 




$table .=  <<<ENDINFO
<tr>
<td><a href ="client_details.php?user_id=$user_id">$username </a></td>
<td>$image_id</td>
<td></td>
<td>c</td>
<td><img src="'.$target.$photo.'" width="100" height="100">
</td>
</tr>
ENDINFO;
}

?>

我看不出上面的代码有什么问题,所以请检查一些东西

  • 您可以将查询结果变为var_dump(),或者在类似于编辑器的工作台中运行查询吗?当您这样做时,图像上传中是否有与您在图像名称字段中看到的值相对应的图像

  • image_是否上载此php页面所在文件夹的子文件夹?这可能是一个显而易见的问题,但有时是这样简单的问题

  • 还是不工作?然后,请在您的问题中发布查询结果的前几行,我会看看是否可以进一步帮助您


  • 请提供带有一些示例数据的表结构以及您的期望值result@FathahRehmanP好的,让我们简单一点,我希望用户名来自tish_用户,图像名称来自tish_图像这是要显示的图像如果您提供两个表的创建表脚本,那么它将非常有用useful@FathahRehmanP