Error loading a value from a table Row

madpad

Member
All
I am trying to load a value from a certain record of Table2 into Table3, based on the Wiki code, but running into errors. Could someone point how I can pull a table record into the current table?

Attachments show my table structures and the code I am using...Thanks in advance.
 

Attachments

  • 1.jpg
    1.jpg
    10.1 KB · Views: 164
  • 2.jpg
    2.jpg
    22.5 KB · Views: 164
  • 4.jpg
    4.jpg
    50.2 KB · Views: 171
  • 3.jpg
    3.jpg
    37.7 KB · Views: 160
Well there are several issues here in your code.
First of all, your query will return an array but the calc element can't return an array, so you can only return one value in one calc element.
Also, you need to have
Code:
return .... ;
at the end of the code to actually return the expected value.
 
Thank you, Sir.
I did add a return on the last line per your suggestion. Still returns nothing. Here is the code I have now -
---------
$db = JFactory::getDbo();
$query = $db->getQuery(true);

$query
->select(array('Status'))
->from('tbl2')
->where('Period = \'2011\'' and 'Member = \'1\'')

$db->setQuery($query);
$Status = $db->loadObjectList();
return $Status;
------------------
I have changed all the fields to 'tbl2.field' from simply 'field'. Still no result.
Although I have put in values for Member and Period, eventually I would like to put placeholders...where 'Member' = '{tbl3___Member}'. Is it ok to put placeholders here?
 
Your query is still wrong.

It should read like this

Code:
$query
    ->select('Status')
    ->from($query->quoteName('tbl2')
    ->where($query->quoteName('Period') . ' = '2011 and ' . $query->quoteName('Member') . ' = 1');

$db->setQuery($query);
$Status = $db->loadResult();

You can use placehoder in the query. That should give this
Code:
where($query->quoteName('Period') . ' = ' . $query->quote( '{tablename_elementname}') . ' and ' . $query->quoteName('Member') . ' = ' . $query->quote( '{tablename_elementname}'))

But to be sure you should put this line after $db->setQuery($query);
Code:
echo $query->dump(); exit;
to see what your query looks like and to run it into phpMyAdmin to see if it returns the expected results.
 
I tried various permutations and combinations of the above code...but it still does not pull the record. In simple words, I want this code to pull Status from Tbl2 based on the values of Member and Period1 in the current (tbl3) table.

Attached is the code I am using now...
 

Attachments

  • 3.jpg
    3.jpg
    61 KB · Views: 161
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top