获取每条记录两次-PHP、MySql


Getting each record two times - PHP, MySql

我有一个搜索表单,你可以根据需要选择,选择后,当你点击提交按钮时,你会被重定向到搜索列表页面,在那里你可以查看用户的列表,一切都很好,但问题是我每个记录都得到两次。

来自以下代码:

<?php
include_once('dbconn.php');
$looking_for = $_POST['looking_for'];
$religion = $_POST['religion'];
$mother_tongue = $_POST['mother_tongue'];
$query = "SELECT * FROM user INNER JOIN profile_description where gender like '".$looking_for."' AND religion like '%".$religion."%' AND mother_tongue like '%".$mother_tongue."%'";
$result = mysql_query($query);
while ($result_row = mysql_fetch_row(($result))){
$profile_created_by = $result_row[1];
$religion = $result_row[6];
$mother_tongue = $result_row[7];
$city = $result_row[15];
$community = $result_row[16];
$height = $result_row[17];
$education_level = $result_row[23];
$education_field = $result_row[24];
$working_with = $result_row[26];
$describe_yourself = $result_row[28];
?>
<div class="search_list wrap">
<p>Profile created by <?php echo ucwords($profile_created_by); ?></p>
<div class="search_list_image">
<img src="img/groom-1.jpg">
</div>
<div class="profile_basic">
<label class="label">Age / Height</label><div class="info">25, <?php echo $height; ?></div>
<div class="clearfix"></div><div class="spacer_4"></div>
<label class="label">Religion</label><div class="info"><?php echo ucwords($religion); ?></div>
<div class="clearfix"></div><div class="spacer_4"></div>
<label class="label">Mother Tongue</label><div class="info"><?php echo ucwords($mother_tongue); ?></div>
<div class="clearfix"></div><div class="spacer_4"></div>
<label class="label">Community</label><div class="info"><?php echo ucwords($community); ?></div>
<div class="clearfix"></div><div class="spacer_4"></div>
<label class="label">Location</label><div class="info"><?php echo ucwords($city); ?></div>
<div class="clearfix"></div><div class="spacer_4"></div>
<label class="label">Education</label><div class="info"><?php echo ucwords($education_level); ?> - <?php echo ucwords($education_field); ?></div>
<div class="clearfix"></div><div class="spacer_4"></div>
<label class="label">Profession</label><div class="info"><?php echo ucwords($working_with); ?></div>
<div class="clearfix"></div>
</div>
<div class="search_list_link">
<a href="#">View full profile</a>
</div>
<div class="search_list_content">
<p><?php echo $describe_yourself; ?></p>
</div>
</div>
<?php } ?>

有人能告诉我我在这里做错了什么吗?

您应该在Join中添加要连接两个表的列。否则,当用户有多个profile_description时,用户表中的每一列都将重复

这可能会解决您的问题。

SELECT DISTINCT(Table_ID),info, ... FROM user INNER JOIN profile_description where gender like '".$looking_for."' AND religion like '%".$religion."%' AND mother_tongue like '%".$mother_tongue."%'";

如果你有多个ID相同的条目,这是行不通的。在这种情况下,它只会抓取第一个条目。