Pulling records from another table.

15 posts by 3 authors in: Forums > CMS Builder
Last Post: October 25, 2010   (RSS)

Still getting the same message:
Notice: Undefined offset: 0 in /home/davgol20/goldcastleholdings.com/property.php on line 26

Goto this Suite page to see the Leasing Agent info (it works great)
http://173.236.177.72/suite.php?510-514-3

Go to this page where I want it to work but it won't:
http://173.236.177.72/property.php?name=Castle%20Building

Re: [Dan Maitland] Pulling records from another table.

By Chris - October 22, 2010

Hi Dan,

I suspect that either (a) your 'agent' field in your "Castle Building" record is blank or references an agent that no longer exists or (b) your 'agents' section has a 'name' field which is automatically trying to filter based on the query string (to fix this, we'll set 'allowSearch' => false).

Let's add some sanity-checking code to make sure that we're getting records back, as well as disabling allowSearch in your lookup: (new code in red)

list($buildingsRecords, $buildingsMetaData) = getRecords(array(
'tableName' => 'buildings',
'limit' => '1',
));
$buildingsRecord = @$buildingsRecords[0];
if (!$buildingsRecord) { header("HTTP/1.0 404 Not Found"); print "Building not found!"; exit; }

list($agentsRecords, $agentsMetaData) = getRecords(array(
'tableName' => 'agents',
'where' => mysql_escapef('num = ?', $buildingsRecord['agent']),
'allowSearch' => false,
'limit' => 1,
));
$agentsRecord = @$agentsRecords[0];
if (!$agentsRecord) { header("HTTP/1.0 404 Not Found"); print "Agent not found!"; exit; }


Does that help? Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Pulling records from another table.

after adding the code you gave me now all I get is a white page with this message:

Agent not found!

Re: [chris] Pulling records from another table.

Forgot to add the "'allowSearch' => false, " now it's working perfectly.

Why would one page need that extra cose and the other doesn't? They are both trying to do the same thing so why would one work and not the other?