pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: ripley@gazeta.pl
To: pgsql-php@postgresql.org
Subject: Re: Interactive querys - final version
Date: Tue, 23 Dec 2003 09:37:18 +0100 (CET)
Message-ID: <1072168639040.ew4.ripley@gazeta.pl> (raw)
In-Reply-To: <200312221803.55855.skoot@qi.pl>

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)



view thread (2+ messages)  latest in thread

Message-ID: <1072168639040.ew4.ripley@gazeta.pl>
Permalink:  ../1072168639040.ew4.ripley@gazeta.pl/
Also on:    postgresql.org/message-id/1072168639040.ew4.ripley@gazeta.pl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: ripley@gazeta.pl
  Subject: Re: Interactive querys - final version
  In-Reply-To: <1072168639040.ew4.ripley@gazeta.pl>
  References: <200312221803.55855.skoot@qi.pl> <1072168639040.ew4.ripley@gazeta.pl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox