如何在php中显示数据库中具有相同id的图像之一?
此代码逐行显示所有图像,但我只希望显示一个图像,在数据库中,我有4个相同id下的图像,从中我希望显示一个图像如果您希望使用相同id仅显示1个图像,则按分组如何在php中显示数据库中具有相同id的图像之一?,php,html,Php,Html,此代码逐行显示所有图像,但我只希望显示一个图像,在数据库中,我有4个相同id下的图像,从中我希望显示一个图像如果您希望使用相同id仅显示1个图像,则按分组 <?php $sqlget = "SELECT * FROM news_events,news_events_images WHERE news_events.id = news_events_images.newsId"; $sqldata = mysql_query($sqlget) or die('error getting da
<?php
$sqlget = "SELECT * FROM news_events,news_events_images WHERE news_events.id = news_events_images.newsId";
$sqldata = mysql_query($sqlget) or die('error getting data');
echo " <table class=\"table table-striped table-hover\" style=\"width:100%;\"> <thead><th colspan=\"2\"> <h3 style= \"font-family:Georgia;font-size:22px;text-transform:capitalize; text-align:center; color:#ec1e2e; \">News and events</h3> </th>";
echo"</thead><tbody>";
while ($row = mysql_fetch_array($sqldata, MYSQLI_ASSOC)) {
echo "<tr><td colspan=\"2\" style=\"width:100%;text-align:center;font-size:16px;font-weight:bold;padding:3em 0em;\">";
echo $row['Title'];
echo "</td></tr><tr><td style=\"width:30%;\">";
echo "<img src=\"Admin/images/newsImages/";
echo $row['image'];
echo "\"";
echo" class=\"image-responsive\" style=\"display:block; width:100%; height:auto;\">";
echo "</td><td style=\"width:70%;text-align:justify;\">";
echo $row['description'];
echo "</td>
</tr>";
}
echo "</tbody></table>";
?>
有关更多信息,请按分组
如果您只想使用同一id显示一张图像,请分组
<?php
$sqlget = "SELECT * FROM news_events,news_events_images WHERE news_events.id = news_events_images.newsId";
$sqldata = mysql_query($sqlget) or die('error getting data');
echo " <table class=\"table table-striped table-hover\" style=\"width:100%;\"> <thead><th colspan=\"2\"> <h3 style= \"font-family:Georgia;font-size:22px;text-transform:capitalize; text-align:center; color:#ec1e2e; \">News and events</h3> </th>";
echo"</thead><tbody>";
while ($row = mysql_fetch_array($sqldata, MYSQLI_ASSOC)) {
echo "<tr><td colspan=\"2\" style=\"width:100%;text-align:center;font-size:16px;font-weight:bold;padding:3em 0em;\">";
echo $row['Title'];
echo "</td></tr><tr><td style=\"width:30%;\">";
echo "<img src=\"Admin/images/newsImages/";
echo $row['image'];
echo "\"";
echo" class=\"image-responsive\" style=\"display:block; width:100%; height:auto;\">";
echo "</td><td style=\"width:70%;text-align:justify;\">";
echo $row['description'];
echo "</td>
</tr>";
}
echo "</tbody></table>";
?>
有关更多信息,请按分组
您可以在查询中使用group by news\u events.id,然后在sql查询中使用
LIMIT 0,1
显示1个图像。所有图像都相同吗?您可以在查询中使用group by news\u events.id,然后在sql查询中使用LIMIT 0,1
显示1个图像。所有图像都相同吗?