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
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
...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?
Chris
Re: [chris] Close, but patially clueless - trying to pull relational records to display output
By Codee - October 12, 2009
Terry
Re: [equinox69] Close, but patially clueless - trying to pull relational records to display output
By Chris - October 13, 2009
Did you get this sorted out? I didn't get a message with a URL from you.
Chris
Re: [chris] Close, but patially clueless - trying to pull relational records to display output
By Codee - October 14, 2009
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
<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!
Chris
Re: [chris] Close, but patially clueless - trying to pull relational records to display output
By Codee - October 15, 2009
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
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
Sorry I didn't respond sooner!
If it's not too much trouble, can you please explain what your workaround is?
Chris
Re: [chris] Close, but patially clueless - trying to pull relational records to display output
By Codee - October 19, 2009
No "sorries" needed. I REALLy appreciate the product and all the support.
So I'll explain the challenge better and the workaround. If nothing else, good for a chuckle.
Challenge: After inserting the code that forces makes/models (that are in a separate heirarchical tables) to display their text names instead of their numerica equivalents; the code for the inventory viewer partially broke. If there were no records for a particular inventory search then there were several errors on the page instead of getting "no records for that search". If you remove the inserted code, then the inventory search works perfectly (if no records get the "no records for that search" message)...so it was definitely resulting from the additional, but necessary code. What would have solved it one way for me would be if there were no records for that type of search (by dealer), that the "view dealer records" link just wouldn't show. However, as I wrote in the earlier forum message I didn't know how to do that either. So I didn't know how to fix the newly inserted code I received, and I didn't know how to modify the viewer page to only show the "view dealer ads" link when there was inventory for that dealer. So I improvised.
In other words, I cheated the code, but hopefully temporarily. In the Dealer Info section, I put in a check box for "display dealer ad link". Leave unchecked if there are no dealer ads. Then on the viewer page we only reveal the "view dealer ads" link if that box has been checked. So, it works, for the moment; but I would like a more appropriate way to do it.