Jump to content


Photo

$etomite->resultset problem


  • Please log in to reply
5 replies to this topic

#1 invi

invi

    Etomite Forum Newbie

  • Member
  • 4 posts

Posted 14 October 2010 - 03:37 PM

First off, my PHP-skills force me to copy code and fiddle a bit with it. Most of the time that's enough, but I've run into a problem I can't solve with fiddling.

On my website I want one a of links generated from a db-table, the call to the list is in the template. On another part of the page I want to use some data from the link clicked. I've used code copied from the new parsechunk tutorial to generate the list of links, fiddled with it to meet my demands, and it works perfectly. On the other part of the page I use a similar snippet to GET one record out of the table (based on link/url) and use the data to fill some fields in a form. That part also works.

My problem is, the one record pulled with the GET is the first one in my list of links; after that the complete list from the query in the list-snippet is added. As I plan to use both the list and the code in a multitude of snippets (and chunks) it's pretty annoying. My current attempt to drop the contents of the $etomite->resultset end up in errors or no notable change. My l33t code-fiddling-skills seems to lack in a certain way.

Things I tried:
  • unset($etomite->resultset); in both snippets (the list and the form), both top and bottom of the code.
  • renaming the $etomite->resultset to $etomite->resultset_x in one of the snippets

Anyone got any suggestions on how to clear the resultset or change the code in such a way it'll 'work' the second run on the same page?

Edited by invi, 14 October 2010 - 03:58 PM.


#2 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 14 October 2010 - 05:38 PM

invi, can you please post the snippet code you are working with so we can be of more help...??? It may be something relatively simple or it may be a problem with the implementation...

#3 invi

invi

    Etomite Forum Newbie

  • Member
  • 4 posts

Posted 15 October 2010 - 04:31 AM

invi, can you please post the snippet code you are working with so we can be of more help...??? It may be something relatively simple or it may be a problem with the implementation...

The problem also occurs when I call the same snippet twice on a page, so here's the one:
if($rs = $etomite->dbQuery("
SELECT * 
FROM {$etomite->db}ovb_leerlingen WHERE leefgroep = '".$grp."'"))
{
  while($row = $etomite->fetchRow($rs))
  {
    // manipulate data rows
    $row['link'] = $etomite->makeURL(1,'','?lln='.$row['id']);
    //append $row to $etomite->resultset[];
    $etomite->resultset[] = $row;
  }
  mysql_free_result($rs);
  if(!isset($etomite->resultset)) return;
  return $etomite->parseChunk(
    $name = 'lln_listall',
    $params = array(
      'rows'=>$etomite->resultset,
      'table_caption'=>'Sample Top Caption',
      'sample_tag'=>'<p><em>Sample Tag Text</em></p>',
      'dummy_tag'=>'<p><b>Etomite "IS" a template engine, dummy!</b></p>'
    ),
    $prefix = '{',
    $suffix = '}'
  );
}
The results from the first call get added to the results of the second call. I tried it with the original code (the code from the tutorial) and there it doesn't happen (though the results from the tutorial gets added to the results from my own snippet...)

#4 Cris D.

Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts

Posted 15 October 2010 - 08:25 AM

If the results are appending and you only want the one, if you declare $etomite->resultset= array(); prior to the if($rs = $etomite->dbQuery( it will clear it priot to building the new array - whether this is an object used by the parser - I don't know without looking - so maybe it's easier to just declare the array as a local variable instead of an etomite class object (I'd try $resultset = array(); $resultset[]= $row; instead of $etomite->resultset[] = $row;).

Edited by Cris D., 15 October 2010 - 08:35 AM.


#5 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 15 October 2010 - 01:04 PM

I think Cris D. nailed it... Also make sure you use a non-cached snippet call, [!Snippet!], instead of [[Snippet]]... Doing so can resolve some unexpected quirks...

#6 invi

invi

    Etomite Forum Newbie

  • Member
  • 4 posts

Posted 15 October 2010 - 02:53 PM

declare $etomite->resultset= array();

That one did the trick. Thanks!

I tried the snippet on non-cached already, but that didn't help. Anyway, problem solved.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users