Thread: Interactive querys

Interactive querys

From
Ângelo Marcos Rigo
Date:
Hi

I want to build an aplication to perform interactive
querys where the user can select the fields he want to
query and still reorder the query itens.

This can be done only using php or javascript or flash
are needed?

Thanks in advance

=====
Ângelo Marcos Rigo
AMR Informática
(51) 3348 0870
Rua Pe. Alois Kades 400/210
Porto Alegre /RS/Brasil
http://amr.freezope.org
angelo_rigo@yahoo.com.br



______________________________________________________________________

Yahoo! Mail: 6MB, anti-spam e antivírus gratuito! Crie sua conta agora:
http://mail.yahoo.com.br

Re: Interactive querys

From
Marek Lewczuk
Date:
Ângelo Marcos Rigo wrote:
> Hi
>
> I want to build an aplication to perform interactive
> querys where the user can select the fields he want to
> query and still reorder the query itens.
>
> This can be done only using php or javascript or flash
> are needed?

It depends from your choice - for example you can use only PHP and
fields names can be send by $_GET variables, e.g. Ofcourse it can be
done with javascript - it will be more dynamic.

ML



Re: Interactive querys

From
Ângelo Marcos Rigo
Date:
Using two textareas side by side, with the query
options coming from the left?

=====
Ângelo Marcos Rigo
AMR Informática
(51) 3348 0870
Rua Pe. Alois Kades 400/210
Porto Alegre /RS/Brasil
http://amr.freezope.org
angelo_rigo@yahoo.com.br



______________________________________________________________________

Yahoo! Mail: 6MB, anti-spam e antivírus gratuito! Crie sua conta agora:
http://mail.yahoo.com.br

Re: Interactive querys

From
Date:
------ Wiadomość oryginalna ------


Od:    Ângelo Marcos Rigo <angelo_rigo@yahoo.com.br>


Data:  2003-12-15 14:23


Temat: Re: [PHP] Interactive querys




:-> Using two textareas side by side, with the query


:-> options coming from the left?


:->


:-> =====


:-> Ângelo Marcos Rigo


---------------------------------------------


Hi Angelo


It's possible to write it using only PHP


1. First - you have to put on the web-form all the fields, that user
will use to customer his query - like:


 - checkboxes - whose correspond to columns, wich user want to put
in a query


 - text fields - where user can enter the expression used to "where"
condition


 - lists fields - which for egzample includes positions "asceding",
"descending"


 - some "hidden" fields, that will provide some addtitional
information to the script.php which will build the query


- in the tag < form action="..." > use the method=post


//I always name this fileds using full name of column + some keyword
- it helps ;)//


2. Second - you have only to build your query string - using
conditions "if..." :


start with:


$query_str = "select ";


if ($_POST["id_chbox"] = 1)


     $query_str += $_POST["id_chbox"];


if ($_POST["name_chbox"] = 1)


       $query_str += ", ".$_POST["id_name"];


..............


and so on


You can also try to make this script "universal" by using iterations
through $_POST variables - its possible to write something like


for ($n=0; n < ...;$n++)


   {


   $_POST[$cols[$n]."_chbox"]............


   }


The only minus of this method is that it can take some time :)


I hope it helps


Asia Sledzik


//sory for readers for this additional enters beetween every, but my
e-mail server put them all and I can't help for it//



------------ R E K L A M A ------------
Gotowy do drogi? Swiateczny Kalendarz SAS zaprasza!
Przez 24 dni oferujemy 24 oferty specjalne do Europy i USA.
Tylko na stronie http://www.scandinavian.net/ (wybierz Polske)

Re: Interactive querys

From
Date:
Hi Angelo




First take my apologise for my mistake  ;)


It shouldn't be  $query_str += ", ".$_POST["id_name"];, but
$query_str .= ", ".$_POST["id_name"];




The '.' it's a concatenation of strings and variables:


if $_POST["id_name"]=15,  it gives you ", 15"




The '$query_str .=' it is taken from C language - it is equivalent
to $query_str = $query_str.", ".$_POST["id_name"]




Aaa.... and don't forget about adding '' when you want to insert a
string into query: "'".$_POST["name_tx"]."'" //I always forget about
it  =D//




Happy To Helped


Asia Sledzik


------ Wiadomość oryginalna ------


Od:    Ângelo Marcos Rigo <angelo_rigo@yahoo.com.br>


Data:  2003-12-22 12:23


Temat: Re: [PHP] Interactive querys




:-> Thank´s Sledzik


:-> Now it is very clear! the query will just concatenate


:-> :


:-> Let me ask about the . in: .$_POST["id_name"] :-> from :


:->


:-> $query_str += ", ".$_POST["id_name"];


:->


:-> this syntax is not familiar to me yet , what it does?


:->


:-> thank´s in advance





:-> ----- Wiadomo?? oryginalna ------


:->


:->


:-> Od:    Ângelo Marcos Rigo <angelo_rigo@yahoo.com.br>


:-> Data:  2003-12-15 14:23


:-> Temat: Re: [PHP] Interactive querys


:->


:-> :-> Using two textareas side by side, with the query


:-> :-> options coming from the left?


:-> :-> =====


:-> :-> Ângelo Marcos Rigo




:-> ---------------------------------------------




:-> Hi Angelo




:-> It's possible to write it using only PHP




:-> 1. First - you have to put on the web-form all the


:-> fields, that user


:-> will use to customer his query - like:


:->  - checkboxes - whose correspond to columns, wich user


:-> want to put in a query




:->  - text fields - where user can enter the expression


:-> used to "where"


:-> condition


:->


:->


:->  - lists fields - which for egzample includes


:-> positions "asceding",


:-> "descending"


:->


:->


:->  - some "hidden" fields, that will provide some


:-> addtitional


:-> information to the script.php which will build the


:-> query


:->


:->


:-> - in the tag < form action="..." > use the method=post


:->


:->


:-> //I always name this fileds using full name of column


:-> + some keyword


:-> - it helps ;)//


:->


:->


:-> 2. Second - you have only to build your query string -


:-> using


:-> conditions "if..." :


:->


:->


:-> start with:


:->


:->


:-> $query_str = "select ";


:->


:->


:-> if ($_POST["id_chbox"] = 1)


:->


:->


:->      $query_str += $_POST["id_chbox"];


:->


:->


:-> if ($_POST["name_chbox"] = 1)


:->


:->


:->        $query_str += ", ".$_POST["id_name"];


:->


:->


:-> ..............


:->


:->


:-> and so on


:->


:->


:-> You can also try to make this script "universal" by


:-> using iterations


:-> through $_POST variables - its possible to write


:-> something like


:->


:->


:-> for ($n=0; n < ...;$n++)


:->


:->


:->    {


:->


:->


:->    $_POST[$cols[$n]."_chbox"]............


:->


:->


:->    }


:->


:->


:-> The only minus of this method is that it can take some


:-> time :)


:->


:->


:-> I hope it helps


:->


:->


:-> Asia Sledzik


:->



------------ R E K L A M A ------------
Gotowy do drogi? Swiateczny Kalendarz SAS zaprasza!
Przez 24 dni oferujemy 24 oferty specjalne do Europy i USA.
Tylko na stronie http://www.scandinavian.net/ (wybierz Polske)

Re: Interactive querys

From
Mariusz Pekala
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The idea is nice. I am using similiar technique in my work, but you commited
some mistakes in the code. It may cause some anger/frustration amongst newbie
ones. :-)

ripley@gazeta.pl (pon 22. grudzień 2003 11:46):
> ------ Wiadomość oryginalna ------
> Od:    Ângelo Marcos Rigo <angelo_rigo@yahoo.com.br>
> Data:  2003-12-15 14:23
>
> Temat: Re: [PHP] Interactive querys
[...]
> 2. Second - you have only to build your query string - using
> conditions "if..." :
>
> start with:
>
> $query_str = "select ";
>
> if ($_POST["id_chbox"] = 1)

It sets the value of possibly non-existing $_POST["id_chbox"] to 1, that
expression is evaluated as TRUE, thus the following is always executed.

>      $query_str += $_POST["id_chbox"];

You, probably, wanted to say: $query_str .= ' id';

> if ($_POST["name_chbox"] = 1)
>        $query_str += ", ".$_POST["id_name"];

Same here... == instead of =, and .= instead of += and ' name' instead of
$_POST['id_name'];

Also, real code should check whether any field has been already inserted in
the $query_str before the comma will be used as separator.

> ..............
>
> and so on
>
> You can also try to make this script "universal" by using iterations
> through $_POST variables - its possible to write something like
>
> for ($n=0; n < ...;$n++)
>    {
>    $_POST[$cols[$n]."_chbox"]............
>    }
>
> The only minus of this method is that it can take some time :)

A few dozens of iterations should be pretty fast. And this method is more
'elegant' than linear - if( x==1)... else if( x==2) ... else if( x==3).. way.

>
> I hope it helps
> Asia Sledzik

Me too... ;-)
  Mariusz
- --
        [http://skoot.qi.pl for GPG keys]
"A computer programmer is someone who, when told to "Go to Hell", sees
the "Go to", rather than the destination, as harmful."
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE/5yOxvkWo15WV1rkRArQUAJ9Yg6hjGUSrDjq665TpX6Wfe/X3YwCfU0vh
3Lpd8mZ51K6AvnqUax7B1zs=
=+pJE
-----END PGP SIGNATURE-----



Re: Interactive querys - final version

From
Date:
Hi :)




I'm really happy that we started so interesting discussion :-)


Mariusz is right !


So I'm putting here the right version of example, that we make
together


/including the problem with commas/:




$query_str = "select ";


if ($_POST["id_chbox"] == 1)


    $query_str .= " id,";


if ($_POST["name_chbox"] == 1)


    $query_str .= " name,";




.......and at the and cut the last 1 sign of this string - which /if
at least one checkbox is checked/ surely will be a comma


dealing with "no checkbox checked" that another subject ;-)




And - this is for Angelo - It would be great if you share code, that
you're writting!




Happy To Help


Asia Sledzik




------ Wiadomość oryginalna ------


Od:    Mariusz Pekala <skoot@qi.pl>


Data:  2003-12-22 18:02


Temat: Re: [PHP] Interactive querys




:-> -----BEGIN PGP SIGNED MESSAGE-----


:-> Hash: SHA1


:->


:-> The idea is nice. I am using similiar technique in my work, but
you commited


:-> some mistakes in the code. It may cause some anger/frustration
amongst newbie


:-> ones. :-):->


:-> ripley@gazeta.pl (pon 22. grudzień 2003 11:46):


:-> > ------ Wiadomość oryginalna ------


:-> > Od:    Ângelo Marcos Rigo <angelo_rigo@yahoo.com.br>


:-> > Data:  2003-12-15 14:23:-> >


:-> > Temat: Re: [PHP] Interactive querys


:-> [...]


:-> > 2. Second - you have only to build your query string - using


:-> > conditions "if..." :


:-> > start with:


:-> > $query_str = "select ";


:-> > if ($_POST["id_chbox"] = 1)


:-> It sets the value of possibly non-existing $_POST["id_chbox"] to
1, that


:-> expression is evaluated as TRUE, thus the following is always
executed.


:-> >      $query_str += $_POST["id_chbox"];


:->


:-> You, probably, wanted to say: $query_str .= ' id';


:-> > if ($_POST["name_chbox"] = 1)


:-> >        $query_str += ", ".$_POST["id_name"];


:-> Same here... == instead of =, and .= instead of += and ' name'
instead of


:-> $_POST['id_name'];


:-> Also, real code should check whether any field has been already
inserted in


:-> the $query_str before the comma will be used as separator.


:-> > ..............


:-> > and so on


:-> > You can also try to make this script "universal" by using
iterations


:-> > through $_POST variables - its possible to write something
like


:-> >


:-> > for ($n=0; n < ...;$n++)


:-> >    {


:-> >    $_POST[$cols[$n]."_chbox"]............


:-> >    }


:-> >


:-> > The only minus of this method is that it can take some time :)


:->


:-> A few dozens of iterations should be pretty fast. And this
method is more


:-> 'elegant' than linear - if( x==1)... else if( x==2) ... else if(
x==3).. way.


:->


:-> >


:-> > I hope it helps


:-> > Asia Sledzik


:->


:-> Me too... ;-)


:->   Mariusz


:-> - --


:->         [http://skoot.qi.pl for GPG keys]


:-> "A computer programmer is someone who, when told to "Go to
Hell", sees


:-> the "Go to", rather than the destination, as harmful."



------------ R E K L A M A ------------
Gotowy do drogi? Swiateczny Kalendarz SAS zaprasza!
Przez 24 dni oferujemy 24 oferty specjalne do Europy i USA.
Tylko na stronie http://www.scandinavian.net/ (wybierz Polske)

Re: Interactive querys - final version

From
Ângelo Marcos Rigo
Date:
Hi all

No problem in sharing the code to the list as i have
done it before in others projects!

I am still looking for a no javascrit way to
reordenate the items that will compose the query.
Maybe an array function do this job i will research

The original idea come from a delphy ready made plugin
that use buttons that can be selected and reordenated,


So i think in the future the html <div></div> can play
the role of the buttons, but the first version will be
with two textareas

Grretings from Brasil




=====
Ângelo Marcos Rigo
AMR Informática
(51) 3348 0870
Rua Pe. Alois Kades 400/210
Porto Alegre /RS/Brasil
http://amr.freezope.org
angelo_rigo@yahoo.com.br



______________________________________________________________________

Conheça a nova central de informações anti-spam do Yahoo! Mail:
http://www.yahoo.com.br/antispam


Re: Interactive querys - reordering

From
Date:
------ Wiadomość oryginalna ------


Od:    Ângelo Marcos Rigo <angelo_rigo@yahoo.com.br>


Data:  2003-12-23 12:03


Temat: Re: [PHP] Interactive querys - final version




:-> Hi all


:->


:-> No problem in sharing the code to the list as i have


:-> done it before in others projects!


:->


:-> I am still looking for a no javascrit way to


:-> reordenate the items that will compose the query.


:-> Maybe an array function do this job i will research


:->


:-> The original idea come from a delphy ready made plugin


:-> that use buttons that can be selected and reordenated,


:->


:->


:-> So i think in the future the html <div></div> can play


:-> the role of the buttons, but the first version will be


:-> with two textareas


:->


:-> Grretings from Brasil





:-> =====


:-> Ângelo Marcos Rigo


------------------------------------------




Hi :)




It is possible to perform custom actions on PHP - similar to Java


The only problem is, that you will have to reload all your webpage:




Generally my idea of simulating java by PHP divides in two:


- putting links <a href...></a> which loads the same PHP script but
with different values of variables provided by get


    like you're seeing next


    and in neccesary parts of script php use the condition if


    if ($_GET["var"] == "ascending")


        {....}


    if ($_GET["var1"] == "descending")


        {....}




- putting several submit buttons in a form - every submit has got
the same name but different value


 you read submit buttons in the same way as other fields:
$_POST["submit_name"] - value of this variable will simply depends


on which of submit buttons has the user clicked before.




and in neccesary parts of script php use the condition if


if ($_POST["submit1"] == "ascending")


    {....}


if ($_POST["submit1"] == "descending")


    {....};








Now your example:


---- BEWARE - IT DOESN'T WORK CORRECTLY !!! ------------


I've got one problem with passing by get string that contents spaces
- in my case server can't do this include




But I'm sending it to you - probably you will now how to "heal" this
script...






OK I'm assuming that you have one form with checkboxes, list and
script "query-doit.php" in action


in "query-doit.php" you build the query_str with $_POST[] variables,
send to database and


read the result and display the web page .




My idea is to add divide this script into 2 scripts


- the first is responsible for only building the query_str form
checkboxes, lists etc. and sending the complete query string to


the second script with instruction include("http:
//page_adress/showresult.php?query_str=".$query_str."&sort_type=up")
;




 - second script, responsible only for querying to database and
displaying the result, which will receive by get text of the query
and the variable responsible for type of order




put in it, this two links


<a href="showresult.php?query_str=<? echo $query_str ?
>&sort_type=up>Up</a>


<a href="showresult.php?query_str=<? echo $query_str ?
>&sort_type=down>Down</a>




and after retriving a result from the database and putting it to
variable $result


if ($_GET["sort_type"]=="up")


   {


     echo "<textarea>";


    .....read the $result variable with the for ($n=0;
$n<=pg_num_rows($result)-1; $n++) {}


   echo "</textarea>";


    }


if ($_GET["sort_type"] == "down")


    {


    echo "<textarea>";


    .....read the $result with for ($n=pg_num_rows($result)-1;$n>=0;
$n--) {...}


    echo "</textarea>;


    }




If the user want's to reorder the positions of the query "down" - he
will clik the link titled Down, which will cause the script to
reload himself,


sending himself the same querystring but the different sort_type






Is that it what you're asking about?




Hope To Help


Asia Sledzik





------------ R E K L A M A ------------
Gotowy do drogi? Swiateczny Kalendarz SAS zaprasza!
Przez 24 dni oferujemy 24 oferty specjalne do Europy i USA.
Tylko na stronie http://www.scandinavian.net/ (wybierz Polske)