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

Your name:

Reply:


Posted by Rami Elomaa on 04/13/07 18:47

strawberry kirjoitti:
> On Apr 13, 6:23 pm, Rami Elomaa <rami.elo...@gmail.com> wrote:
>> Vince Morgan kirjoitti:
>>
>>
>>
>>> "strawberry" <zac.ca...@gmail.com> wrote in message
>>> news:1176450464.524325.95990@n59g2000hsh.googlegroups.com...
>>>> On Apr 13, 1:51 am, "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 ";
>>> The line above is looking for a value from a field named $conditionString.
>> No, it doesn't. Variables inside a double quoted string are parsed. It's
>> perfectly valid code. The example you gave would also work, but it's
>> totally unnecessary.
>>
>> Just try this and you'll learn something fun:
>>
>> <?php
>>
>> $cat = 'dog';
>>
>> echo "I have an animal in my hand and the animal is a $cat. <br />";
>> echo 'I have an animal in my hand and the animal is a $cat. <br />';
>>
>> ?>
>>
>> --
>> Rami.Elo...@gmail.com
>>
>> "Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
>> usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
>
> Thanks Rami,
>
> I knew from the echoes that my statements were valid.

Yes, and I never doubted that, I was just replying to Vince who was
giving you silly advices.. :)

> Unfortunately,
> the mysrc class doesn't seem to agree with me :-(
>
> To recap. No matter what I try I just can't seem to pass this...
>
> foreach ($_GET as $condition_key => $condition_value) {
> $condition[] =" `$condition_key` = '$condition_value' ";
> $condition_keys[] = "$condition_key";
> $condition_values[] = "'$condition_value'";
> }
> if(is_null($condition)){
> $conditionString = " 1 ";
> }else{
> $conditionString = implode('AND', $condition);
> $conditionKeysString = implode(',',$condition_keys);
> $conditionValuesString = implode(',',$condition_values);
> }
>
> as arguments to this...
>
> class mysrc extends drasticsrcmysql {
> protected function select($conditionString){
> $query = "SELECT * FROM $this->table WHERE $conditionString";
> $res = mysql_query($query . $this->orderbystr, $this->conn) or
> die(mysql_error());
> return ($res);
> }
>
> protected function add($conditionKeysString,$conditionValuesString){
> $query = "INSERT INTO $this->table ($conditionKeysString) VALUES
> ($conditionValuesString)";
> mysql_query($query, $this->conn) or die(mysql_error());
> if (mysql_affected_rows($this->conn) == 1) return(true); else
> return(false);
> }
>
> ...unless I pass a bogus column name: Unknown column
> 'false_column_name' in 'where clause'
>

I'd say the query works fine, just that the resultset is not visible
outside the method for some reason. The error message you get would
indicate that the query is passed and executed, and the problem may lie
elsewhere. I seem to recall having a similar problem when passing a
result set from one function to another. I don't remember the situation
exactly, but as I recall it, the resultset would disappear, perhaps
because it only existed in the scope of that function. So if you are
testing the resultset outside the class, it might be that the resultset
has already been cleared, even though it was executed in a civilized
manner. Study the resultset within the method to see if it exists
there... If it does, then you've at least discovered the problem and the
next step is to make it persist. HTH.

--
Rami.Elomaa@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze

[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

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