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] . ', ';
}
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@professionalcomputersolut ions 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>'.getCompanyCategorie s($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.
@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>'.getCompanyCategorie
When I use return, it returns the results within the table cell. When I use echo it echoes the results above the table.
ASKER
ok, so I solved it like this...
Is there a more efficient way to do it?
thanks,
brian
$allMyCategories = '';
while($myCategories = mysql_fetch_array( $companyCategories )){
$allMyCategories = $allMyCategories . $myCategories[value] . ', ';
}
return $allMyCategories;
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
with the exception of a variable name change that's my comment
ASKER
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
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
test without the where statement.