PHP Classes

Conditional queries

Recommend this page to a friend!

      DrasticTools  >  All threads  >  Conditional queries  >  (Un) Subscribe thread alerts  
Subject:Conditional queries
Summary:Adding a WHERE clause
Messages:15
Author:laptopalias
Date:2007-04-08 15:21:22
Update:2007-04-16 22:02:36
 
  1 - 10   11 - 15  

  11. Re: Conditional queries   Reply   Report abuse  
Picture of laptopalias laptopalias - 2007-04-15 16:31:06 - In reply to message 10 from dd
Hi Olav,

I tried the updated class, but still no joy :-(

+++++++++++++++++++++++++++++++++++++++++++++++
1. This works:

$k1="Continent";$k2="Code";$v1="Europe";$v2="GBR";
$options = array(
"defaultcols" => array($k1=>$v1,$k2=>$v2)
);

+++++++++++++++++++++++++++++++++++++++++++++++

2. This just hangs, with no error mesage:

ExampleGrid3a.php?Continent=Europe&Code=GBR
-------------------------------------------

$options = array(
"defaultcols" => $_GET );

+++++++++++++++++++++++++++++++++++++++++++++++

3. This fails with the error "Unknown column 'foo' in 'where clause'":

ExampleGrid3a.php?foo=Europe&Code=GBR
-------------------------------------

$options = array(
"defaultcols" => $_GET );
+++++++++++++++++++++++++++++++++++++++++++++++

Any ideas?

  12. Re: Conditional queries   Reply   Report abuse  
Picture of dd dd - 2007-04-15 19:16:59 - In reply to message 11 from laptopalias
Difficult to say. At least 1. proves that the defaultcols setting works.
The rest is a matter of passing URL arguments in your code.
I suppose in 2. the Europe and Code values are getting through (otherwise you would got an error such as in 3) but something fails on the values of the fieds. In 3 it is clearly a matter of not having a MySQL column named foo, so this makes sense.
Can't say more about this from a distance.

  13. Re: Conditional queries   Reply   Report abuse  
Picture of laptopalias laptopalias - 2007-04-16 14:35:33 - In reply to message 12 from dd
So it sounds like you can't replicate this behaviour!?!

So does pasting this into Example3a.php work?

foreach($_GET AS $key => $value){
$options = array(
"defaultcols" => array($key=>$value)
);
}
$src = new drasticsrcmysql($server, $user, $pw, $db, $table, $options);


Strange. I was wondering if it was some setting in my php.ini file, but everything seems OK there. :-(


  14. Re: Conditional queries   Reply   Report abuse  
Picture of dd dd - 2007-04-16 19:36:10 - In reply to message 13 from laptopalias
well, I replicated the
$options = array(
"defaultcols" => $_GET );
solution and found out what goes wrong.
The grid uses an Ajax call to get the data into it.
This Ajax call is built within the javascript code and it calls the same .php file from which the javascript was invoked (in your case exampleGrid3a.php) with a number of new GET variables (like op=v and start=0 etc).
This second call again reaches your code and then this code stores the new GET variables into the defaultcols setting, which causes it to build a WHERE string that does not make sense.
So, a complicated story, but the conclusion is that, how sadly, the grid wasn't developed for this purpose.
I don't see a quick workaround. Of course you can use cookies or read the information from a file or another source that you can reach from your php code, but not via the GET parameters, as far as I can see now.

  15. Re: Conditional queries   Reply   Report abuse  
Picture of laptopalias laptopalias - 2007-04-16 22:02:36 - In reply to message 14 from dd
Hi Olav,

Thanks for looking into that. Disappointing answer - but at least it suggests that I'm not going mad! Well,...

Anyway, I'll try the cookies route instead.

Once again, thank you.

 
  1 - 10   11 - 15