php-general Digest 5 Nov 2010 08:27:12 -0000 Issue 7022

Topics (messages 309319 through 309330):

Re: How to code in PHP an onchange event in a <select>?
        309319 by: Nicholas Kell
        309320 by: Bastien
        309328 by: admin.buskirkgraphics.com
        309330 by: Paul Waring

Re: Weird preg issue
        309321 by: Alex Nikitin
        309322 by: Alex Nikitin

Re: php-general-digest-unsubscr...@lists.php.net not working?
        309323 by: Kevin Kinsey

Re: Pros/Cons of using mysqli prepared statments
        309324 by: Matt Graham
        309325 by: Jay Blanchard
        309326 by: Alex Nikitin
        309327 by: knl.bitflop.com
        309329 by: Tamara Temple

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Nov 4, 2010, at 3:23 PM, Tomás Corrales Lemoine wrote:

> Hi, List,
>  
> I have this two files (“index.php” and “include.php”). They both work fine, 
> but I want to substitute the code for de onchange event in the <select> tag. 
> Can I use PHP to code this event? How?
>  
> Thanks.
>  
>  
>  
> index.php:
>  
> <?php
>  
> echo '<html><body>';
>  
> include_once 'include.php';
>  
> $mysql_link = tcl_MySQL_ConnectToServer('localhost', 'user', 'password');
>  
> tcl_MySQL_OpenDataBase($mysql_link, 'production');
>  
> $query = 'SELECT DISTINCT recipe.product_id, product.description FROM recipe, 
> product WHERE recipe.product_id = product.product_id ORDER BY 
> product.description';
> $result = tcl_MySQL_DataQuery($mysql_link, $query);
>  
> tcl_FillComboBox($result, 'Product', 'product_id', 'description', 
> 'alert(\'Alert Message\')');
>  
> tcl_MySQL_CloseConnection($mysql_link);
>  
> echo '</body></html>';
>  
> ?>
>  
>  
>  
> include.php:
>  
> <?php
>  
> function tcl_MySQL_CloseConnection($link) {
>       mysql_close($link);
> }
>  
> function tcl_MySQL_ConnectToServer($host, $user, $password) {
>       $link = mysql_connect($host, $user, $password);
>       if (!$link) {
>             die('No se pudo conectar: '.mysql_error());
>       }
>       echo '<h3>User '.strtoupper($user).' connected to MySQL server.</h3>';
>       return $link;
> }
>  
> function tcl_MySQL_DataQuery($link, $query) {
>       return mysql_query($query, $link);
> }
>  
> function tcl_MySQL_OpenDataBase($link, $database) {
>       mysql_select_db($database, $link);
> }
>  
> function tcl_FillComboBox($result, $label, $col1, $col2, $onchange) {
>       echo '<label>'.$label.'</label><select onchange="'.$onchange.'"><option 
> value="">';
>       while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
>             echo '<option value="'.$line[$col1].'">'.$line[$col2];
>       }
>       echo '</select>';
> }
>  
> ?>
>  
> 
> -- 
> Aeropuerto Internacional Frank País García de Holguín. -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php



I think that what you are looking for is javascript.

Check this out: 
http://www.decompile.com/dataflex/webappserver/combobox_auto_submit.htm


--- End Message ---
--- Begin Message ---

On 2010-11-04, at 4:23 PM, Tomás Corrales Lemoine <to...@hog.ecasa.avianet.cu> 
wrote:

> Hi, List,
> 
>  
> 
> I have this two files (“index.php” and “include.php”). They both work fine, 
> but I want to substitute the code for de onchange event in the <select> tag. 
> Can I use PHP to code this event? How?
> 
>  
> 
> Thanks.
> 
>  
> 
>  
> 
>  
> 
> index.php:
> 
>  
> 
> <?php
> 
>  
> 
> echo '<html><body>';
> 
>  
> 
> include_once 'include.php';
> 
>  
> 
> $mysql_link = tcl_MySQL_ConnectToServer('localhost', 'user', 'password');
> 
>  
> 
> tcl_MySQL_OpenDataBase($mysql_link, 'production');
> 
>  
> 
> $query = 'SELECT DISTINCT recipe.product_id, product.description FROM recipe, 
> product WHERE recipe.product_id = product.product_id ORDER BY 
> product.description';
> 
> $result = tcl_MySQL_DataQuery($mysql_link, $query);
> 
>  
> 
> tcl_FillComboBox($result, 'Product', 'product_id', 'description', 
> 'alert(\'Alert Message\')');
> 
>  
> 
> tcl_MySQL_CloseConnection($mysql_link);
> 
>  
> 
> echo '</body></html>';
> 
>  
> 
> ?>
> 
>  
> 
>  
> 
>  
> 
> include.php:
> 
>  
> 
> <?php
> 
>  
> 
> function tcl_MySQL_CloseConnection($link) {
> 
>       mysql_close($link);
> 
> }
> 
>  
> 
> function tcl_MySQL_ConnectToServer($host, $user, $password) {
> 
>       $link = mysql_connect($host, $user, $password);
> 
>       if (!$link) {
> 
>             die('No se pudo conectar: '.mysql_error());
> 
>       }
> 
>       echo '<h3>User '.strtoupper($user).' connected to MySQL server.</h3>';
> 
>       return $link;
> 
> }
> 
>  
> 
> function tcl_MySQL_DataQuery($link, $query) {
> 
>       return mysql_query($query, $link);
> 
> }
> 
>  
> 
> function tcl_MySQL_OpenDataBase($link, $database) {
> 
>       mysql_select_db($database, $link);
> 
> }
> 
>  
> 
> function tcl_FillComboBox($result, $label, $col1, $col2, $onchange) {
> 
>       echo '<label>'.$label.'</label><select onchange="'.$onchange.'"><option 
> value="">';
> 
>       while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
> 
>             echo '<option value="'.$line[$col1].'">'.$line[$col2];
> 
>       }
> 
>       echo '</select>';
> 
> }
> 
>  
> 
> ?>
> 
>  
> 
> 
> -- 
> Aeropuerto Internacional Frank País García de Holguín.
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


Ajax back to the server to run the php

Bastien Koert

--- End Message ---
--- Begin Message ---
OnChange is Javascript.

 

 

I might suggest you get yourself familiar with JQuery.

JQuery makes your life a lot easier when there is a need for client browser
interaction with site scripting.

 

 

 

 

Richard L. Buskirk

 

From: Tomás Corrales Lemoine [mailto:to...@hog.ecasa.avianet.cu] 
Sent: Thursday, November 04, 2010 4:23 PM
To: php-gene...@lists.php.net
Subject: [PHP] How to code in PHP an onchange event in a <select>?

 

Hi, List,

 

I have this two files (“index.php” and “include.php”). They both work fine,
but I want to substitute the code for de onchange event in the <select> tag.
Can I use PHP to code this event? How?

 

Thanks.

 

 

 

index.php:

 

<?php

 

echo '<html><body>';

 

include_once 'include.php';

 

$mysql_link = tcl_MySQL_ConnectToServer('localhost', 'user', 'password');

 

tcl_MySQL_OpenDataBase($mysql_link, 'production');

 

$query = 'SELECT DISTINCT recipe.product_id, product.description FROM
recipe, product WHERE recipe.product_id = product.product_id ORDER BY
product.description';

$result = tcl_MySQL_DataQuery($mysql_link, $query);

 

tcl_FillComboBox($result, 'Product', 'product_id', 'description',
'alert(\'Alert Message\')');

 

tcl_MySQL_CloseConnection($mysql_link);

 

echo '</body></html>';

 

?>

 

 

 

include.php:

 

<?php

 

function tcl_MySQL_CloseConnection($link) {

      mysql_close($link);

}

 

function tcl_MySQL_ConnectToServer($host, $user, $password) {

      $link = mysql_connect($host, $user, $password);

      if (!$link) {

            die('No se pudo conectar: '.mysql_error());

      }

      echo '<h3>User '.strtoupper($user).' connected to MySQL server.</h3>';

      return $link;

}

 

function tcl_MySQL_DataQuery($link, $query) {

      return mysql_query($query, $link);

}

 

function tcl_MySQL_OpenDataBase($link, $database) {

      mysql_select_db($database, $link);

}

 

function tcl_FillComboBox($result, $label, $col1, $col2, $onchange) {

      echo '<label>'.$label.'</label><select
onchange="'.$onchange.'"><option value="">';

      while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {

            echo '<option value="'.$line[$col1].'">'.$line[$col2];

      }

      echo '</select>';

}

 

?>

 


-- 
Aeropuerto Internacional Frank País García de Holguín. 


--- End Message ---
--- Begin Message ---
On 04/11/10 20:23, Tomás Corrales Lemoine wrote:
I have this two files (“index.php” and “include.php”). They both work
fine, but I want to substitute the code for de onchange event in the
<select> tag. Can I use PHP to code this event? How?

xajax will allow you to call PHP code as if it was JavaScript:

http://www.xajax-project.org/

Paul

--- End Message ---
--- Begin Message ---
Ah, i seem to have figured out the problem here... if you run a
preg_match_all it will return

    [0] => Array
        (
            [0] => And the cow says
            [1] =>
            [2] => Moo"
            [3] =>
        )

And preg_replace is global by default, so in order for this to work
correctly, not sure about the elegantly part, but you can just limit
preg_replace

preg_replace('/(?:(?!"[a-zA-Z\s]*").)*/', '', $str, 1);

and that seems to work correctly...

Neat... kinda...

On Thu, Nov 4, 2010 at 3:47 PM, Alex Nikitin <niks...@gmail.com> wrote:

> Hi,
>
> I'm kind of new to this list, and so if there have been discussions about
> this, i am not quite aware of them (i tried searching), but i ran across
> this issue and i figured it would be interesting enough to show you guys
> here:
>
> I was looking for a way to replace all the text in a string that doesn't
> match a pattern with nothing (therefore string in, only part of the string
> that matches my pattern out), one line with no arrays in the middle; and i
> guess there is a way to do this with temp variables, well i know there is,
> but i kind of wanted a more elegant solution, so i came up with this match
> line
>
> $str = 'And the cow says "Mooo"';
> preg_match('/(?:(?!"[a-zA-Z\s]*").)*/', $str, $matches);
> print_r($matches);
>
> output:
> Array
> (
>     [0] => And the cow says
> )
>
> so i was pretty happy to see that, so if i pass that expression to
> preg_replace it should, hopefully, replace that text with nothing, and i
> theoretically should be left with "Mooo", which was my goal originally, so i
> run
>
> print_r(preg_replace('/(?:(?!"[a-zA-Z\s]*").)*/', '', $str));
>
> output:
> "
>
> ... Hardly what i was expecting... Any ideas? bug, something i'm not
> getting, something in the way preg works?
>
> Thanks in advance,
>
>
>
> ~ Alex
>

--- End Message ---
--- Begin Message ---
but that doesnt work if you add something after the "Mooo".... *sigh*.....
well it gets kept


On Thu, Nov 4, 2010 at 3:47 PM, Alex Nikitin <niks...@gmail.com> wrote:

> Hi,
>
> I'm kind of new to this list, and so if there have been discussions about
> this, i am not quite aware of them (i tried searching), but i ran across
> this issue and i figured it would be interesting enough to show you guys
> here:
>
> I was looking for a way to replace all the text in a string that doesn't
> match a pattern with nothing (therefore string in, only part of the string
> that matches my pattern out), one line with no arrays in the middle; and i
> guess there is a way to do this with temp variables, well i know there is,
> but i kind of wanted a more elegant solution, so i came up with this match
> line
>
> $str = 'And the cow says "Mooo"';
> preg_match('/(?:(?!"[a-zA-Z\s]*").)*/', $str, $matches);
> print_r($matches);
>
> output:
> Array
> (
>     [0] => And the cow says
> )
>
> so i was pretty happy to see that, so if i pass that expression to
> preg_replace it should, hopefully, replace that text with nothing, and i
> theoretically should be left with "Mooo", which was my goal originally, so i
> run
>
> print_r(preg_replace('/(?:(?!"[a-zA-Z\s]*").)*/', '', $str));
>
> output:
> "
>
> ... Hardly what i was expecting... Any ideas? bug, something i'm not
> getting, something in the way preg works?
>
> Thanks in advance,
>
>
>
> ~ Alex
>

--- End Message ---
--- Begin Message ---
Paul M Foster wrote:
On Thu, Nov 04, 2010 at 12:34:35PM -0400, Daniel P. Brown wrote:

On Thu, Nov 4, 2010 at 12:33, Daniel P. Brown <daniel.br...@parasane.net> wrote:
   If you continue to have issues, let me know and I will remove you.
    From the list, that is, to be clear.  Not the Earth.

Dang! I was just about to send you a list of people to remove! ;-}

Paul

Lord-a-mercy, yes!!! Daniel, what license for this service?  BSD?
CC?  GPL?  :-D

Kevin Kinsey


--- End Message ---
--- Begin Message ---
"Jay Blanchard" <jblanch...@pocket.com> didst scribe:
> using stored procedures has a lot of advantages. If you need to
> change your SQL you can do it in one spot. It reinforces MVS or
> modular coding behavior, the SP becomes very re-usable. Security
> is improved. Performance can be improved. You can put the bulk of
> the data handling on the database where it really belongs because
> SP's can perform complex operations complete with control
> structures. Lastly it simplifies your PHP code.

Just don't go too far.  Years and years ago, I worked on a project where there
were about 100 stored procedures, many of which were 200-300 lines long, many
of which called other stored procedures which called other stored procedures. 
These procedures were frequently modified.  Attempting to debug this can of
worms full of Pandora's boxes was like pulling hen's teeth.  The initial idea
was for the app to do almost nothing but call stored procedures and display
results; this caused a number of problems which were ignored or solved badly.

(I'd almost forgotten that horrible mess where I had no input on anything
design-related, thank you for reminding me....)

-- 
Matt G / Dances With Crows
The Crow202 Blog:  http://crow202.org/wordpress/
There is no Darkness in Eternity/But only Light too dim for us to see


--- End Message ---
--- Begin Message ---
[snip]
Just don't go too far. 
[/snip]

I absolutely agree! Doing SP's for SP sake is not desired and be truly
careful about cascading the procedures. And always, ALWAYS document your
code and put copious comments in the SP's.

--- End Message ---
--- Begin Message ---
One thing to remember is that dealing with results from prepared statements
is different then getting results from queries, so if you are using both,
confusion can easily set in (and lets face it, prepared statements arent
always the best thing to use)... if its of any help, i have written a class
to work around that, instantiate it with a query or result object from a
statement and you get a uniform way to get the result array...

http://pastebin.com/sAhZJcNX

~ Alex

On Thu, Nov 4, 2010 at 5:38 PM, Jay Blanchard <jblanch...@pocket.com> wrote:

> [snip]
> Just don't go too far.
> [/snip]
>
> I absolutely agree! Doing SP's for SP sake is not desired and be truly
> careful about cascading the procedures. And always, ALWAYS document your
> code and put copious comments in the SP's.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
On Thu, 4 Nov 2010 02:48:55 -0500
Tamara Temple <tam...@tamaratemple.com> wrote:

> I'm wondering what the advantages/disadvantage of using prepared  
> statements with mysqli are. I'm used to using the mysqli::query and  
> mysqli::fetch_assoc functions to deal with retrieving data and
> bulding my sql statement in php code.

Take a look at PHP PDO also.
 
> Tamara Temple
>       -- aka tamouse__
> tam...@tamaratemple.com
> 
> 
> "May you never see a stranger's face in the mirror."
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

--- End Message ---
--- Begin Message ---

On Nov 4, 2010, at 6:36 AM, Jay Blanchard wrote:

[snip]
If you have a query in your PHP code, which you are going to be
executing a lot, even if you are using prepared statements, you can go
one further by creating a stored procedure. Now the SQL server will
only ever need to compile the statement once. No matter how many times
it is used. You only need to supply the data which will be type
appropriate.
[/snip]

I second this, using stored procedures has a lot of advantages. If you
need to change your SQL you can do it in one spot. It reinforces MVS or
modular coding behavior, the SP becomes very re-usable. Security is
improved. Performance can be improved. You can put the bulk of the data
handling on the database where it really belongs because SP's can
perform complex operations complete with control structures. Lastly it
simplifies your PHP code.


(dangit, i sent this from the wrong address initially)

I do know about stored procedures and have used them where appropriate (retrieving the entire contents of a table, one record from a table, etc.). It was the prepared statements that I haven't had experience with. I wasn't away that these were precompiled. That does make them more attractive for heavily executed pulls. On the other hand, the seem to require more intense maintenance than just changing some lines of code in a file if need be. (I assume prepared statements don't share the same efficiency of maintenance that stored procedures do across applications.)



--- End Message ---

Reply via email to