Link to home
Start Free TrialLog in
Avatar of befidled
befidled

asked on

help returning results from query

I've got the following code below however it is only returning one record and it should be returning multiple records. What did  I do wrong?

 
<?php

$companyCategories = mysql_query("SELECT wp_rg_lead_detail.id, 
					wp_rg_lead_detail.lead_id, 
					wp_rg_lead_detail.form_id, 
					wp_rg_lead_detail.field_number, 
					wp_rg_lead_detail.value
				FROM wp_rg_lead_detail
				WHERE wp_rg_lead_detail.lead_id = $leadID AND wp_rg_lead_detail.field_number > 126 AND wp_rg_lead_detail.field_number < 152 ");

while($myCategories = mysql_fetch_array( $companyCategories )){
	
	return $myCategories[value] . ',  ';

}

Open in new window

Avatar of Tyler Laczko
Tyler Laczko
Flag of Canada image

you have where it = leadid. are you sure you db have multiple values.

test without the where statement.
Avatar of vr6r
vr6r

Replace "return" with "echo"

return ends execution of the function when you call it and gives you the result.  In this case it will just spit out the first row of your result set and then quit.
ASKER CERTIFIED SOLUTION
Avatar of Michael701
Michael701
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of befidled

ASKER

@professionalcomputersolutions Yes, multiple rows are returned.

@vr6r The problem when I use echo, is that it doesn't put the results where I want them.

For instance, I am calling the function like this:

echo '<td>'.getCompanyCategories($leadID).'</td>';

When I use return, it returns the results within the table cell. When I use echo it echoes the results above the table.
ok, so I solved it like this...

$allMyCategories = '';
	
	while($myCategories = mysql_fetch_array( $companyCategories )){
		$allMyCategories = $allMyCategories . $myCategories[value] . ',  ';
	}
	
	return $allMyCategories;

Open in new window


Is there a more efficient way to do it?

thanks,
brian
well i definately agree!

with the exception of a variable name change that's my comment
Hey Michael,

thanks! I just saw that you had posted pretty much the same answer to my solution, I didn't see your posting when I posted mine.

thanks!

brian