如何从两个表中进行选择,只显示1个表中的一个项目和第二个表中的多个项目?

时间:2022-03-11 11:59:42

I have two table user and Image table I want to select only the profile picture in the image table and in the user table I can select 3 fields . I tried using the Inner join but I can’t see no image displayed and no error . bellow is my code

我有两个表用户和图像表我想只选择图像表中的配置文件图片,在用户表中我可以选择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;
}

?>

1 个解决方案

#1


0  

I can't really see anything wrong with the above code, so check a couple of things.

我真的看不出上面的代码有什么问题,所以检查一下。

  1. Can you var_dump() your query result or run your query in an editor like workbench? When you do, are there images in image_uploads that correspond to the values you are seeing in the image_name field including?

    你可以var_dump()你的查询结果或在像workbench这样的编辑器中运行你的查询吗?当你这样做时,image_uploads中的图像是否与你在image_name字段中看到的值相对应?

  2. is image_uploads a subfolder of the folder that this php page is contained in? It may be an obvious question, but sometimes it's something simple like this.

    是image_uploads包含此php页面的文件夹的子文件夹?这可能是一个显而易见的问题,但有时它会像这样简单。

  3. Still not working? Then please post the first couple rows of the query result in your question and I'll see if I can help you further.

    还是行不通?然后,请在您的问题中发布查询结果的前几行,我会看看是否可以帮助您。

#1


0  

I can't really see anything wrong with the above code, so check a couple of things.

我真的看不出上面的代码有什么问题,所以检查一下。

  1. Can you var_dump() your query result or run your query in an editor like workbench? When you do, are there images in image_uploads that correspond to the values you are seeing in the image_name field including?

    你可以var_dump()你的查询结果或在像workbench这样的编辑器中运行你的查询吗?当你这样做时,image_uploads中的图像是否与你在image_name字段中看到的值相对应?

  2. is image_uploads a subfolder of the folder that this php page is contained in? It may be an obvious question, but sometimes it's something simple like this.

    是image_uploads包含此php页面的文件夹的子文件夹?这可能是一个显而易见的问题,但有时它会像这样简单。

  3. Still not working? Then please post the first couple rows of the query result in your question and I'll see if I can help you further.

    还是行不通?然后,请在您的问题中发布查询结果的前几行,我会看看是否可以帮助您。