Skip site navigation (1) Skip section navigation (2)

Re: Interactive querys

From: Mariusz Pekala <skoot(at)qi(dot)pl>
To: pgsql-php(at)postgresql(dot)org
Cc: <ripley(at)gazeta(dot)pl>
Subject: Re: Interactive querys
Date: 2003-12-22 17:02:24
Message-ID: 200312221803.55855.skoot@qi.pl (view raw or flat)
Thread:
Lists: pgsql-php
-----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(at)gazeta(dot)pl (pon 22. grudzień 2003 11:46):
> ------ Wiadomość oryginalna ------
> Od:    Ângelo Marcos Rigo <angelo_rigo(at)yahoo(dot)com(dot)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-----



In response to

Responses

pgsql-php by date

Next:From: ripleyDate: 2003-12-23 08:37:18
Subject: Re: Interactive querys - final version
Previous:From: ripleyDate: 2003-12-22 12:41:46
Subject: Re: Interactive querys

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group