Jump to content

Recommended Posts

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];

Link to comment
https://forums.phpfreaks.com/topic/42096-help-with-limit/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/42096-help-with-limit/#findComment-204237
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.