Advertisement

09.30.2007 at 03:56AM PDT, ID: 22862274
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

PHP Mysql query looping, output multiple rows of data need help!

Asked by pdheady in PHP Scripting Language, PHP and Databases, MySQL Server

Tags: , , , ,

I have some code below that outputs a row with like 11 columns of data.  I need to change the code so that it checks the first table for multiple records based on a contact_ID # and outputs them into additional rows.

For example John Doe has a 2 or 3 loans with bank A. I need to output each loan data record in each row, however many John Doe may have in the database.

Here's my code. Perhaps the query can be written as one entire query then use a while loop??? I didnt architect the database, it's XRMS and I have to work with it.  

<?PHP

// #### -------- get opportunies ids and info ------- ####

$sql = "SELECT
opportunity_id, opportunity_type_id, opportunity_status_id, lender_id, campaign_id, company_id , division_id, user_id, entered_by
FROM opportunities
WHERE contact_id = '" . $contact_id . "'";

$rst = $con->execute($sql);
extract($rst->fields);

// #### -------- get company_name ------- ####

$sql = "SELECT
company_name
FROM companies
WHERE company_id = '" . $company_id . "'";

$rst = $con->execute($sql);
extract($rst->fields);


// #### -------- get loan requested amount ------- ####

$sql = "SELECT
amount AS loan_requested FROM opportunity_amounts
WHERE opportunity_amount_type_id = 1
AND opportunity_id = '" . $opportunity_id . "'";

$rst = $con->execute($sql);
extract($rst->fields);

// #### -------- get credit line amount ------- ####

$sql = "SELECT
amount AS credit_line FROM opportunity_amounts
WHERE opportunity_amount_type_id = 2
AND opportunity_id = '" . $opportunity_id . "'";

$rst = $con->execute($sql);
extract($rst->fields);

// #### -------- get financed amount ------- ####

$sql = "SELECT
amount AS financed_amount FROM opportunity_amounts
WHERE opportunity_amount_type_id = 3
AND opportunity_id = '" . $opportunity_id . "'";

$rst = $con->execute($sql);
extract($rst->fields);

// #### -------- get charge auth amount ------- ####

$sql = "SELECT
amount AS charge_auth_amount FROM opportunity_amounts
WHERE opportunity_amount_type_id = 4
AND opportunity_id = '" . $opportunity_id . "'";

$rst = $con->execute($sql);
extract($rst->fields);

// #### -------- get lender short name ------- ####

$sql = "SELECT
lender_short_name FROM lenders
WHERE id = '" . $lender_id . "'";

$rst = $con->execute($sql);
extract($rst->fields);

// #### -------- get the owner of the record ------- ####

$sql = "SELECT
last_name FROM users
WHERE user_id = '" . $entered_by . "'";

$rst = $con->execute($sql);
extract($rst->fields);

// #### -------- get the CF instance_id ------- ####

$sql = "SELECT
instance_id FROM cf_instances
WHERE key_id = '" . $contact_id . "'";

$rst = $con->execute($sql);
extract($rst->fields);


// #### -------- get the CF loan rate data ------- ####

$sql = "SELECT
value as loan_rate FROM cf_data
WHERE instance_id = '" . $instance_id . "'
AND field_id = 25";

$rst = $con->execute($sql);
extract($rst->fields);

// #### -------- get the CF account number data ------- ####

$sql = "SELECT
value as account_number FROM cf_data
WHERE instance_id = '" . $instance_id . "'
AND field_id = 24";

$rst = $con->execute($sql);
extract($rst->fields);

}


// THE HTML OUTPUT OF THE ROWS

<tr bgcolor="#FFFFFF">
<td align="center"><?php echo render_edit_button("Edit", 'button', "javascript: location.href='worksheets/worksheet.php?opportunity_id=$opportunity_id';") ?></td>
<td align="center" style="line-height: 25px; vertical-align: middle"><?=$opportunity_status_short_name?></td>
<td align="center" style="line-height: 25px; vertical-align: middle"><a href="/xrms/companies/one.php?company_id=<?=$company_id?>"><?=$company_name?></a></td>
<td align="center" style="line-height: 25px; vertical-align: middle"><?=$loan_requested?></td>
<td align="center" style="line-height: 25px; vertical-align: middle"><?=$credit_line?></td>
<td align="center" style="line-height: 25px; vertical-align: middle"><?=$financed_amount?></td>
<td align="center" style="line-height: 25px; vertical-align: middle"><?=$charge_auth_amount?></td>
<td align="center" style="line-height: 25px; vertical-align: middle"><? if ($lender == 0) { echo "ADS"; } else { echo "$lender_short_name"; } ?></td>
<td align="center" style="line-height: 25px; vertical-align: middle"><? if ($loan_rate == "") { echo "Not Set"; } else { echo "$loan_rate"; } ?></td>
<td align="center" style="line-height: 25px; vertical-align: middle"><? if ($account_number == "") { echo "Not Set"; } else { echo "$account_number"; } ?></td>
<td align="center" style="line-height: 25px; vertical-align: middle"><?=$last_name?></td>
</tr>

Start Free Trial
[+][-]09.30.2007 at 06:52AM PDT, ID: 19987004

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP Scripting Language, PHP and Databases, MySQL Server
Tags: php, multiple, mysql, rows, query
Sign Up Now!
Solution Provided By: trickyidiot
Participating Experts: 2
Solution Grade: A
 
 
[+][-]09.30.2007 at 09:59AM PDT, ID: 19987379

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.01.2007 at 04:32AM PDT, ID: 19989946

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10.01.2007 at 10:06AM PDT, ID: 19992138

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.01.2008 at 06:41AM PDT, ID: 22360105

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09.05.2008 at 09:06PM PDT, ID: 22405756

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_1_20070628