[英]How to select from two tables and display only one item from 1 table and many from the second table?
我有两个表用户和图像表,我只想在图像表中选择个人资料图片,在用户表中我可以选择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_uploads中是否存在与您在image_name字段中看到的值相对应的图像,包括?
是image_uploads这个php页面所在文件夹的子文件夹吗? 这可能是一个显而易见的问题,但有时却像这样简单。
还是行不通? 然后,在您的问题中发布查询结果的前几行,我会看看是否能为您提供进一步的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.