Date: 09/19/00
- Next message: Max Derkachev: "[phplib] $sess->mode='post' workaround"
- Previous message: Florent Berenger: "Re: [phplib] Once again: Phplib with Flash?"
- Next in thread: Alexander Aulbach: "Re: [phplib] query_sql and metadata"
- Reply: Alexander Aulbach: "Re: [phplib] query_sql and metadata"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Please, if you have any questions about Query_SQL, ask me directly, cause
I'm not permanently reading this mailinglist.
On Fri, 15 Sep 2000, Rex Byrns wrote:
}I have been trying to understand how to use query_sql. Evidently I
}understand just enough to be really confused.
Ehem... sorry, short explanations had never been my strength. :->>
}Does anyone out there have any better examples or words of wisdom on how to
}implement the power of these tools?
}I need anything that can help me juggle form data better.
Ok. You have a form for example
-------------------------------------
<form>
<input name=hugo>
<input name=bla>
</form>
-------------------------------------
and you have a table defined as follows:
create table (hugo varchar(40),bla varchar(40));
Ist this easy enough till now? :-)
Now the Program which understands how to insert the data from the form is
just:
-------------------------------------------------------------------------------
<?php
# we're using the old type of inclusion PHPLIBs
include("db_mysql.inc");
include("query_sql.inc");
class myquerysql extends Query // (or in the last update the name is Query_SQL)
{
/* class definition as you do it usualy with db_mysql */
var $Database = 'test';
}
$db=new myquerysql;
$db->query($db->insert_clause("mytable",$db->capture_vars("mytable")));
?>
-------------------------------------------------------------------------------
That's all!
[ok, of course it is a little bit more difficult in practical, and for more complicated
tables, but indeed this listing will work (and is working)]
Remember: Query_Sql is thought for bigger tables as a helper to create more
or less complex queries or parts of it.
}I also would like any advice one might have on doing searches.
You mean the function fireball_clause()?
}I search through 5 different fields. If the user uses "AND", of course the
}search words must both exist in the same field. I would like to replace all
}"AND" queries with "OR" then parse each row and display it if it meets the
}"AND" requirement. (e.g. "Rex AND Texas" -- would return properly if Rex is
}in table.name and Texas is in table.state)
}
}clear as mud?
Hm. Not very. I don't understand the question but I try to repeat it in
my words:
You have a search-string "Rex AND Texas". You make the following call:
-----------------------------------------------------------
$output=$db->fireball_clause("Rex AND Texas","(field1='{s}' and field2='{s}')");
-----------------------------------------------------------
Now $output holds two variables:
-----------------------------------------------------------------------
$output[0] ="( (field1='Rex' and field2='Rex') OR (field1='AND' and field2='AND') OR
(field1='Texas' and field2='Texas') )"
$output[1] ="'Rex' OR 'AND' OR 'Texas'"
-----------------------------------------------------------------------
Ok, you want to have another function, let's call it booool_clause(), which
"understands" the word "AND" as the identifier for the former "+".
Ok. This should be easy, I have thought some times about that it would be
easy to rewrite this function into two functions. One functions, which
scanns the string for the logical comparison operators and the other which
will do a query out of the resulting expression.
The problem is, that I have too less time to make this (even if this would
be fun of course) and I won't promise anything (I have too often promised
too much)
But let's have a view into the source. I think the
fireball_clause()-function is well documented. There are several parts in
this function.
Part 1 will normalize the string, this means that it will for example replace the
string '"Texas Rex"' to 'Texas_Rex'.
Part 2 makes an array out of the found words.
Part 3 will scan the resulting words to form in
Part 4 an expression out of it and in
Part 5 a WHERE-part of a query.
Intstructions, how to do it:
----------------------------
Just take this function and make a copy and call the new function
booool_clause() for example.
Then you have to change Part 3, cause there is the logic which tells the
following part, what to do with it. It is very easy to understand: Part 3
creates two temporary arrays $t and $s. $s holds the word which we are using
and $t holds the operator/logic, which should be used for the word.
In our example $s and $t are looking like follows:
S: Rex|AND|Texas
T: 1 | 1 | 1
You only have to change part 3 that $s and $t are looking like this:
S: Rex|Texas
T: + | +
Some ideas to do it: Change the logic inside of the for-loop of part 3, that
it scans for the word "AND" and if so, the word before it ($s[$cnt-1]) and the
word after it ($s[$cnt+1]) will change their operator to "+"
($t[$cnt-1]='+' and $t[$cnt+1]='+'). Then don't store the word "AND" inside
$s and $t, just go to the next word.
Hum, you have to think a while, how to do it, cause this sounds to be easier,
than it is (I have a logical failure in my explanations above, do you see
it?).
--SSilk - Alexander Aulbach - Herbipolis/Frankonia Minoris - (0931)22032
--------------------------------------------------------------------- To unsubscribe, e-mail: phplib-unsubscribe <email protected> For additional commands, e-mail: phplib-help <email protected>
- Next message: Max Derkachev: "[phplib] $sess->mode='post' workaround"
- Previous message: Florent Berenger: "Re: [phplib] Once again: Phplib with Flash?"
- Next in thread: Alexander Aulbach: "Re: [phplib] query_sql and metadata"
- Reply: Alexander Aulbach: "Re: [phplib] query_sql and metadata"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

