Close, but patially clueless - trying to pull relational records to display output

12 posts by 2 authors in: Forums > CMS Builder
Last Post: October 26, 2009   (RSS)

By Codee - October 9, 2009

To EXCELLENT product company...
I'm trying to output to a viewer page something very simple, but of course, slightly beyond my ability. In our database we have inventory ad records, some added by dealer accounts (the relational table part), and some by the admin. All ads view to the public fine. What we want to accomplish is a separate page that displays the following:

Dealer Name, Dealer Website Link, Link to Dealer Ads in our Inventory

Using generator code I can display the dealer name and the website link, but pulling the correct link to that dealer's ads from our database isn't quite working correctly.

Here's the page code I'm using that needs help:
top code:
--------
<?php

require_once "/home/content/e/q/u/equipmart/html/emaAdmin/lib/viewer_functions.php";

list($dealer_infoRecords, $dealer_infoMetaData) = getRecords(array(
'tableName' => 'dealer_info',
));

list($inventoryRecords, $inventoryMetaData) = getRecords(array(
'tableName' => 'inventory',
'perPage' => '7',
'orderBy' => 'RAND()',
));
$inventoryRecord =& $inventoryRecords[0]; // get first record

// load referenced records for our fields
beta_lookupRelatedFields(array(
'table' => 'inventory',
'recordList' => &$inventoryRecords,
'fieldList' => array(
'manufacturer', 'model' => 'model', 'equipment_type'
),
));

?>
-------------------

and here's the code to display the table, that repeats for each record...
------------------------
<!--display record code begins-->
<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<h1>Our Dealers, Brokers and Partners</h1>
<?php foreach ($dealer_infoRecords as $record): ?>
<table border="0" cellpadding="5" cellspacing="0" width=100%>
<tr>
<td valign="top" width=50%>
<?php if ($record['dealer_business_name']): ?>
<b/><?php echo $record['dealer_business_name'] ?></b/>
<?php endif ?>
</td>
<td valign="top" width=25%>
<?php if ($record['dealer_website']): ?>
<a href="<?php echo $record['dealer_website'] ?>" target="_blank"><font color="#900000" size="2"><b/>click to visit website</b/></font></a>
<?php endif ?>
</td>
<td valign="top" width=25%>
<?php if ($record['dealer_business_name']): ?>
<a href="inventoryList.php?createdByUserNum=<?php echo $inventoryRecord['createdByUserNum']; ?>">
<font color="#900000" size="2"><b/>click to view ads</b/></font>
</a>
<?php endif ?>
</td>
</tr>
</table>
<?php endforeach; ?>

<?php if (!$dealer_infoRecords): ?>
There are no records available for that search at this time. Click BACK in your browser.<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->
<!--display record code ends-->
---------------------------------

Thanks in advance for any help. If you want to see the visual for the page online, I can PM the URL to whomever wishes to assist.

Re: [equinox69] Close, but patially clueless - trying to pull relational records to display output

By Chris - October 11, 2009

Hi equinox69,

...pulling the correct link to that dealer's ads from our database isn't quite working correctly.


I'm going to need more information to know what the problem is. Can you please send your URL?
All the best,
Chris

Re: [chris] Close, but patially clueless - trying to pull relational records to display output

By Codee - October 12, 2009

Absolutely Chris, I'll PM it to you. Thanks in advance.

Terry

Re: [equinox69] Close, but patially clueless - trying to pull relational records to display output

By Chris - October 13, 2009

Hi Terry,

Did you get this sorted out? I didn't get a message with a URL from you.
All the best,
Chris

Re: [chris] Close, but patially clueless - trying to pull relational records to display output

By Codee - October 14, 2009

Hi Chris,
Not sorted out yet, I'm stuck. I apologize for the delay. We're moving and put in a transfer order with Qwest...to include concurrent services - NOT turning off services at current address. Well, this is one reason I hate Qwest. They cut services to current location and then didn't add services to the new location (because there wasn't a pull wire in 11 feet of conduit). SO, we've been dealing with them to get service restored and service activated. I am sorry for the delay.

Anyway, I'm PMing the login details to you in about 2 min.
Thanks!

Re: [equinox69] Close, but patially clueless - trying to pull relational records to display output

By Chris - October 15, 2009

Hi Terry,

<a href="inventoryList.php?createdByUserNum=<?php echo $inventoryRecord['createdByUserNum']; ?>">

...unable to get the dealers ads to link properly. Also each time the page refreshes all the dealer ad links rotate to be the same dealer number.


$inventoryRecord is a single record. I think you want to change that to $record['createdByUserNum'] so that the data comes from the Dealer_Info row you're iterating over.

I hope this helps!
All the best,
Chris

Re: [chris] Close, but patially clueless - trying to pull relational records to display output

By Codee - October 15, 2009

Chris, I knew it was "close"...that part is perfect now...thanks!

One other question on this...is what string of code is needed to check to see if there are inventory records by each respective dealer so that an error doesn't occur if someone clicks on "click to view ads" but there aren't any created by that user?

Thanks!

Re: [equinox69] Close, but patially clueless - trying to pull relational records to display output

By Codee - October 17, 2009

Hi Chris,
Never mind on the last response (unless you've worked a different solution).

I created a workaround for the issue.

Thanks!

Re: [equinox69] Close, but patially clueless - trying to pull relational records to display output

By Chris - October 19, 2009

Hi equinox69,

Sorry I didn't respond sooner!

If it's not too much trouble, can you please explain what your workaround is?
All the best,
Chris