mcmuney Posted March 10, 2007 Share Posted March 10, 2007 Below is a code from a page that displayes photos based on highest rating; however, this code only shows the top person only, limited to 1. I'd like to show the top 5. I've set the limit to 12, but it doesn't appear to be working: function get_hot_person($gender) { global $db; $hotm_sql="select s1.scm_mem_id,s1.scm_gender,round((s2.sum_/s2.count_),2) score from sc_member s1,sc_rate_score_avg s2,sc_member_images s3 where s1.scm_gender='$gender'and s1.scm_mem_id=s2.scm_mem_id and s3.sci_rating=1 and s3.scm_mem_id= s1.scm_mem_id group by s1.scm_mem_id order by score DESC LIMIT 0,12"; $rate_res1=$db->select_data($hotm_sql); $gender_id=$rate_res1[0][0]; return $gender_id; } $male_id=get_hot_person('Male'); $image_id1=$db->get_imageid_main($male_id); $im_sql1="select * from sc_member_images where sci_id=$image_id1"; $im_res1=$db->select_data($im_sql1); $img_online=$db->mem_img.$im_res1[0][sci_url]; Quote Link to comment https://forums.phpfreaks.com/topic/42096-help-with-limit/ Share on other sites More sharing options...
Orio Posted March 10, 2007 Share Posted March 10, 2007 Try replacing: LIMIT 0,12 With: LIMIT 12 Orio. Quote Link to comment https://forums.phpfreaks.com/topic/42096-help-with-limit/#findComment-204173 Share on other sites More sharing options...
mcmuney Posted March 10, 2007 Author Share Posted March 10, 2007 Nope, didn't do anything. Quote Link to comment https://forums.phpfreaks.com/topic/42096-help-with-limit/#findComment-204177 Share on other sites More sharing options...
per1os Posted March 10, 2007 Share Posted March 10, 2007 Let's go over some basics here, even if you pull data from a MySQL statement you still have to loop through it to get the extra data. I do not see any looping here, unless your hidden code for select_data does that for you. Either way when you do the return portion you are only returning 1 ID, why is that if you want the top 5? You should be returning 5 ID's, am I not right? So the code itself is flawed to begin with. On that note, if you only want the top 5, why limit the SQL to 12? It should be 5 no? Anyhow here is a start of looping and storing the gender_id's into an array. I think you can go from there. function get_hot_person($gender) { global $db; $hotm_sql="select s1.scm_mem_id,s1.scm_gender,round((s2.sum_/s2.count_),2) score from sc_member s1,sc_rate_score_avg s2,sc_member_images s3 where s1.scm_gender='$gender'and s1.scm_mem_id=s2.scm_mem_id and s3.sci_rating=1 and s3.scm_mem_id= s1.scm_mem_id group by s1.scm_mem_id order by score DESC LIMIT 0,5"; $qu = mysql_query($hotm_sql); while ($row = mysql_fetch_assoc($qu)) { $gender_id[] = $row[0]; } //$rate_res1=$db->select_data($hotm_sql); //$gender_id=$rate_res1[0][0]; return $gender_id; } // should now be an array of id's etc $male_id=get_hot_person('Male'); --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42096-help-with-limit/#findComment-204237 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.