trouble with placeholders running query in php

FilMar

Member
I try to run a query in php but have some troubles

When I don't use placeholders, it works
PHP:
    $deRowP = '{rowid}';
    $deRow = 42;

    $user = JFactory::getUser();
    $userid = $user->get('id');

   
    $mydb = JFactory::getDbo();
    $myquery = $mydb->getQuery(true);
    $myquery
        ->select(array('Naam_v as pupil', 'if(i.id is null,"Nee","Ja") as Ingeschreven'))
        ->from($mydb->quoteName('bc_leerlingen', 'll'))
        ->join('LEFT', $mydb->quoteName('bc_inschrijvingen', 'i') . ' ON (' . $mydb->quoteName('i.leerling_id') . ' = ' . $mydb->quoteName('ll.id') . ') and ('.$mydb->quoteName('i.activiteit_id') . ' = '.$mydb->quote($deRow).')')
        ->where($mydb->quoteName('ll.parent_id').' = '.$mydb->quote($userid));
     $mydb->setQuery($myquery);
    $myrows = $mydb->loadAssocList();
   
   
    echo '*'.$deRowP.'*'.$deRow.'*'.$userid.'*<br>'.$myquery.'<br>';
    print_r($myrows);
*42*42*268*
SELECT Naam_v as pupil,if(i.id is null,"Nee","Ja") as Ingeschreven FROM `bc_leerlingen` AS `ll` LEFT JOIN `bc_inschrijvingen` AS `i` ON (`i`.`leerling_id` = `ll`.`id`) and (`i`.`activiteit_id` = '42') WHERE `ll`.`parent_id` = '268'
Array (
[0] => Array ( [pupil] => xxx [Ingeschreven] => Ja )
[1] => Array ( [pupil] => yyy [Ingeschreven] => Nee ) )

But when I use the placeholder (so change $deRow to $deRowP wich hold the id of the current row) it won't run correctly anymore
*42*42*268*
SELECT Naam_v as pupil,if(i.id is null,"Nee","Ja") as Ingeschreven FROM `bc_leerlingen` AS `ll` LEFT JOIN `bc_inschrijvingen` AS `i` ON (`i`.`leerling_id` = `ll`.`id`) and (`i`.`activiteit_id` = '42') WHERE `ll`.`parent_id` = '268'
Array (
[0] => Array ( [pupil] => xxx [Ingeschreven] => Nee )
[1] => Array ( [pupil] => yyy [Ingeschreven] => Nee ) )
As you see, the first pupil (xxx) has now [Ingeschreven] => Nee where it should be "Ja"



What am I doing wrong here?

Greetings,

Filip
 
You can't use placeholders in php files (only in the php code fields).

The confusing thing is if you are debugging with echo... because the placeholder is replaced in the output (AFTER the code has been run with a string like {rowid})
If you do var_dump($deRowP,$deRow) I'm pretty sure you'll get something like
...string(7) 42... (here also the placeholder is replaced afterwards but you can see the string length=7).
 
OK,

What is the best way then to get the rowid here?
It is in a form that is in the footer of a details-form, so I need the rowid from that form.

Many thanks inadvance,

Filip
 
Try with:
PHP:
$form_data = $this->data;
//echo '<pre>' . var_export($form_data, true) . '</pre>';
$form_id = $form_data['your_table_name___id_raw'];
 
OK, works like a charm when I put it in the details-form.

It doen't work that way in an other form in the footer of that details-form.

Maybe a stupid question but when I put a form in the footer I can put filters and so the data is already fitered. (like {fabrik view=list id=45 bc_leerlingen___parent_id_raw=[$my->id]})
I suppose that I can pass the id that way also, but how do I read it there? ({fabrik view=form id=12 deRow=[rowid]})

Thanks,

Filip
 
Or, something else.
Can I create a calc field in a form based on the rowid from the parent form (or passed as parameter)

I have a list of activities and a list of pupils and a list of subscriptions.

In the details of an activity I would like to show the pupils of the logged in user and if they are subscribed or not (and give the possibility to subscribe)
So I have te list of pupils fitered on parent_id in the footer but now I need to check wether they are already subscribed or not.

Many thanks in advance,

Filip
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top