我想用count方法只回顯一個div,一旦mysql查詢顯示8個結果,否則如果顯示7或更少不顯示此div。只顯示div,如果mysql結果顯示8個結果?
繼承人什麼我嘗試做有人可以告訴我在哪裏,我錯了感謝:
<?php
//PHP CODE STARTS HERE
if(isset($_GET['dosearch'])){
// Change the fields below as per the requirements
$db_host="*********";
$db_username="******";
$db_password="******";
$db_name="*****";
$db_tb_atr_name="******";
//Now we are going to write a script that will do search task
// leave the below fields as it is except while loop, which will display results on screen
mysql_connect("$db_host","$db_username","$db_password");
mysql_select_db("$db_name");
$query=mysql_real_escape_string($_GET['query']);
$query_for_result=mysql_query("SELECT *,MATCH(display_name, user_location, sexual_orientation, user_ethnicity, preferred_role, local_station, user_size, weight_st, weight_lb, height_ft, height_in, user_build, user_age) AGAINST ('$query' IN BOOLEAN MODE) AS relevance FROM ptb_stats, ptb_users WHERE ptb_stats.user_id=ptb_users.user_id AND ptb_users.account_type=\"user\" AND MATCH(display_name, user_location, sexual_orientation, user_ethnicity, preferred_role, local_station, user_size, weight_st, weight_lb, height_ft, height_in, user_build, user_age) AGAINST('$query' IN BOOLEAN MODE) ORDER BY relevance DESC LIMIT 8");
echo "<div class=\"search-results\"><div id=\"content2_header\">Members Matching Your Search</div>";
$platinum_count = mysql_num_rows($query_for_result);
while($data_fetch=mysql_fetch_array($query_for_result))
{
echo"<div class=\"image_case\"><a href=\"profile.php?id={$data_fetch['user_id']}\"><img width=93px height=93px src=\"data/photos/{$data_fetch['user_id']}/_default.jpg\"></a>
<div id=\"mod_newest_text12\">{$data_fetch['display_name']}</div>
<div id=\"mod_newest_text14\">{$data_fetch['user_location']}</div></div>
";
}
// only if there are more than 8 users do we want to show our div
if($platinum_count > 7){
// how many default spaces do we need?
$default_profiles_needed = 7 - $platinum_count;
for($i = 1; $i <= $default_profiles_needed; $i++){
echo "<div class=\"morebutton-search21\"><a href=\"search_results.php?query=$query\" class=\"more\">+ view more results</a></div>";
}
}
mysql_close();
}
?>