Automatic conditional row numbering

dimoss

Well-Known Member
Hi,

I am using the Php Events List plugin using the following code inside onLoadDat to autonumber the records of a list:
PHP:
$rownum = $model->limitStart;
$data = $args[0]->data;
foreach ($data as $group) {
   foreach ($group as $row) {
      $rownum++;
      $row->fab_list_able_28_repeat___no = $rownum;
      $row->fab_list_able_28_repeat___no_raw = $rownum;
   }
}
The 'fab_list_able_28_repeat___no' is a single field hidden which is used only for diplaying the row number.
Everything is fine and works as expected.
However I cannot find a way do not numbering rows when the value in the field fab_list_able_28_repeat___wl_raw is 'NER' or 'WDL'
In other words I am trying to have a conditional numbering.

Any ideas are appreciated.

Thanks.
 
Hi Troester,
thanks for that. It worked!

For anyone who might need something similar here is the complete code:
PHP:
$rownum = $model->limitStart;
$data = $args[0]->data;
foreach ($data as $group) {
   foreach ($group as $row) {
   $condition = $row->fab_list_able_28_repeat___wl_raw;
      if ($condition == 'NER' || $condition == 'WDN') continue;
      $rownum++;
      $row->fab_list_able_28_repeat___no = $rownum;
      $row->fab_list_able_28_repeat___no_raw = $rownum;
   }
}
 
Hi,

i open this thread because i would like to find a way using the PHP list plugin to apply the same method updating another field.
Tried this but didnt work:
PHP:
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$app = JFactory::getApplication();
$rownum = $model->limitStart;
$data = $args[0]->data;
foreach ($data as $group) {
   foreach ($group as $row) {
   $condition = $row->fab_list_able_28_repeat___wl_raw;
      if ($condition == 'NER' || $condition == 'WDN') continue;
      $rownum++;
      $row->fab_list_able_28_repeat___no = $rownum;
      $row->fab_list_able_28_repeat___no_raw = $rownum;
$query = "UPDATE fab_list_able_28_repeat SET position = $rownum";
$db->setQuery( $query );
$db->execute();
   }
}

Any idea?
Thanks.
 
A couple of ideas.

It's not "in the way", but what do you need $app for?
Which plugin are you using? You say "PHP List plugin", but it rather seems to be the "PHP Events list plugin"?If (if!) this would work, it would update all "position" cells in the repeat table to that same $rownum value, and each time the condition allows it. Is that what you really want?
Eventually move $query = $db->getQuery(true); into the loop.
Syntax error?
$query = "UPDATE fab_list_able_28_repeat SET position = $rownum";
should probably be
$query = "UPDATE fab_list_able_28_repeat SET position = '{$rownum}'";
or
$query = "UPDATE fab_list_able_28_repeat SET position = ".$rownum;
or
$query = "UPDATE fab_list_able_28_repeat SET position = '$rownum'";
or
$query = "UPDATE fab_list_able_28_repeat SET position = '".$rownum."'";

Sorry, I feel it must be said again: before posting basic "generic" PHP code which "doesn't work" here in the Fabrik forum, please first make sure that you've followed all coding rules, use correct syntax, and so on. Error reporting will help you, as well as var_dump($xyz);exit; and other debugging to avoid using fellow forum members as spellcheckers or free workers -- thank you. ;)
 
Hi @lousyfool

I use PHP list plugin and in every case returns 0 instead of the number.
If you read the previous messages it works fine in PHP Event on load but this for a different purposes as it is created on the fly.
What I want is to use the same loop and update each record.
And yes, there was typo (thanks for that) but unfortunately that was irrelevant.
 
As I said: I think there's no $args[0]->data in list php plugin.

Use var_dump to check and see WIKI for selected row ids and data.
 
Wiki helped :)

PHP:
$app = JFactory::getApplication();
$ids = $app->input->get('ids', array(), 'array');
$count = 0;
foreach($ids as $id)
{
  $count = $count + 1;
  $model->updateRow($id, "fab_doubles.position", $count);
}

In case someone is interested.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top