?
Solved

help returning results from query

Posted on 2011-05-02
7
Medium Priority
?
316 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:befidled
7 Comments
 
LVL 10

Expert Comment

by:Tyler Laczko
ID: 35508324
you have where it = leadid. are you sure you db have multiple values.

test without the where statement.
0
 
LVL 8

Expert Comment

by:vr6r
ID: 35508334
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.
0
 
LVL 19

Accepted Solution

by:
Michael701 earned 2000 total points
ID: 35508360

$answer ='';

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

return $answer;

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:befidled
ID: 35508369
@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.
0
 
LVL 1

Author Comment

by:befidled
ID: 35508395
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
0
 
LVL 19

Expert Comment

by:Michael701
ID: 35508494
well i definately agree!

with the exception of a variable name change that's my comment
0
 
LVL 1

Author Comment

by:befidled
ID: 35509055
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question