我有一个搜索表单,您可以根据需要选择您的选择,选择后,当您点击提交按钮时,您将被重定向到搜索列表页面,您可以在其中检查用户的列表,一切正常但是问题是我每次都会得到两次记录。
从以下代码:
<?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 } ?>
谁能告诉我这里我做错了什么?
答案 0 :(得分:0)
您应该将要添加到哪个列的连接添加到两个表中。否则,当您有多个用户的profile_description
时,用户表中的每一列都将被复制答案 1 :(得分:0)
这可以解决您的问题。
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的条目,则无效。在这种情况下,它只会抓住第一个条目。