Reply to Re: $_GET request -> variable -> object? -> function

Your name:

Reply:


Posted by strawberry on 04/13/07 11:57

On Apr 13, 11:54 am, "Captain Paralytic" <paul_laut...@yahoo.com>
wrote:
> On 13 Apr, 11:52, "strawberry" <zac.ca...@gmail.com> wrote:
>
>
>
> > On Apr 13, 11:10 am, "Captain Paralytic" <paul_laut...@yahoo.com>
> > wrote:
>
> > > On 13 Apr, 01:51, "strawberry" <zac.ca...@gmail.com> wrote:
>
> > > > I'm trying to extend a class (written by others) and was wondering if
> > > > there's a standard a way of passing a $_GET request to a class. Here's
> > > > what I have (see below). If I hardcode $where, something like
>
> > > > $where = " WHERE `firstname` = 'John' "
>
> > > > and then pass it as an argument into the scope of a 'select' function
> > > > then it works fine, but otherwise the query just appears to hang.
>
> > > > I'm deliberately not including the class or class extender at this
> > > > stage, but I'll add them to this thread later if required.
>
> > > > foreach ($_GET as $condition_key => $condition_value) {
> > > > $condition[] =" $condition_key = '$condition_value' ";
> > > > }
> > > > if(is_null($condition)){
> > > > $where = " WHERE 1 ";
> > > > }else{
> > > > $conditionString = implode('AND', $condition);
> > > > $where = " WHERE $conditionString ";
> > > > }
>
> > > echo the final query and pop it into phpmyadmin. One thing I notice is
> > > that you are not puting backtics round the field name ($condition_key)
> > > in your loop.
>
> > You read my mind :-)- Hide quoted text -
>
> > - Show quoted text -
>
> I thought all developers had telepathy functionality. That's how we
> manage to build things even though the users don't know what they want.

Well, here's the class extender, as provided by Olav at Drastic Tools.
The only change I've made to it is to add the $where argument to the
function...

class mysrc extends drasticsrcmysql {
protected function select($where){ //previously select()

$query = "SELECT * FROM $this->table $where "; //previously "SELECT *
FROM $this->table"
$res = mysql_query($query . $this->orderbystr, $this->conn) or
die(mysql_error());
return ($res);
}

If I modify those lines as follows...

$query = "SELECT * FROM $this->table $where ". $this->orderbystr;
$res = mysql_query($query . $this->orderbystr, $this->conn) or
die(mysql_error());

....and pass it a genuine column name, the results page hangs. Aside
from throwing up the predictable 'headers' warning, echoing $query
produces...

SELECT * FROM my_table WHERE `foo` = 'bar' ORDER BY id

....and if I pass it a false column name I get...

Unknown column 'foo' in 'where clause'.

So, now I'm thinking I should scrutinise that orderbystr more closely?
Maybe something else is going on in the class at that point.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация