php-general Digest 31 Oct 2004 20:03:19 -0000 Issue 3085
Topics (messages 200751 through 200773):
Re: MultiSelect List Box in PHP
200751 by: Andy B
200753 by: M. Sokolewicz
200754 by: -{ Rene Brehmer }-
200755 by: -{ Rene Brehmer }-
Re: PHP in CGI ....php.in
200752 by: Christian Ista
Matching *exact* string?
200756 by: Nick Wilson
200758 by: Per Jessen
200759 by: Klaus Reimer
200760 by: Aidan Lister
200761 by: Daniel Schierbeck
200763 by: Daniel Schierbeck
200764 by: Nick Wilson
200765 by: Nick Wilson
200766 by: Nick Wilson
200767 by: Greg Donald
200771 by: Nick Wilson
beginnind and end of the week
200757 by: Jerry Swanson
200762 by: Sebastien Pahud
Re: mysql_select_db error
200768 by: Greg Donald
Re: image files - upload and managment
200769 by: Greg Donald
Reflection API, ReflectionMethod::invoke(object $obj, array $args)
200770 by: Demian Turner
Unable to validate XML with Schema if namespace is specified.
200772 by: Dusty Bin
php command to open a url?
200773 by: Ken Tozier
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
Sorry that doesn't do me a huge bit of good since I have no clue how to
write java in the first place. Does anybody know where I can find or get an
example of php code that shows how to get all the selected items from a
multiselect listbox and loop through them printing them on the screen??
-----Original Message-----
From: Eric Lee [mailto:[EMAIL PROTECTED]
Sent: Sunday, October 31, 2004 3:06 AM
To: Andy B
Subject: Re: [PHP] MultiSelect List Box in PHP
it's just likes you used in normal html & javascript,
but the code that generated to control the ui are now moved to server-sided.
:)
On Sun, 31 Oct 2004 01:33:13 -0500, Andy B <[EMAIL PROTECTED]> wrote:
> Hi.
>
> I was just wondering where I can find info on how to use a MultiSelect
List
> Box with PHP? I need to use it with MYSQL 5.0.0, PHP 4.3.9, and windows XP
> sp2.
>
> Any help/leads would be greatly appreciated.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Eric Lee
--- End Message ---
--- Begin Message ---
---------[ input.html ]----------
<html>
....
<form action="input.php" method="post">
<select name="select[]" multiple>
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
<input type="submit" value="submit" name="submit">
</form>
....
</html>
---------[ ]----------
---------[ input.php ]----------
<?php
print_r($_POST);
?>
---------[ ]----------
---------[ output ]----------
Array
(
[select] => Array
(
[0] => 1
[1] => 2
)
[submit] => submit
)
---------[ ]----------
Above output is with #1 and #2 selected, and #3 not selected. Easy, huh?
- Tul
Andy B wrote:
Sorry that doesn't do me a huge bit of good since I have no clue how to
write java in the first place. Does anybody know where I can find or get an
example of php code that shows how to get all the selected items from a
multiselect listbox and loop through them printing them on the screen??
-----Original Message-----
From: Eric Lee [mailto:[EMAIL PROTECTED]
Sent: Sunday, October 31, 2004 3:06 AM
To: Andy B
Subject: Re: [PHP] MultiSelect List Box in PHP
it's just likes you used in normal html & javascript,
but the code that generated to control the ui are now moved to server-sided.
:)
On Sun, 31 Oct 2004 01:33:13 -0500, Andy B <[EMAIL PROTECTED]> wrote:
Hi.
I was just wondering where I can find info on how to use a MultiSelect
List
Box with PHP? I need to use it with MYSQL 5.0.0, PHP 4.3.9, and windows XP
sp2.
Any help/leads would be greatly appreciated.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
Eric Lee
--- End Message ---
--- Begin Message ---
You can use this to work with. It's something I made some time ago, so it's
probably not the most optimal solution, but it gets the job done...
In this case it builds parameters for a SQL query, but it's easily modified
to suit your needs. The reason it's a 'for' loop and not a 'foreach' is
simply to make it simpler to keep track of how many items there IS in the
list, so that the OR part of the SQL query gets built correctly.
// load field list [multiselect box] from $_POST
$fields = $_POST['fields'];
// walk through all fields and build WHERE clause
for ($i = 0; $i < count($fields); $i++) {
if ($i > 0) {
$addtoquery .= ' OR ';
}
switch ($fields[$i]) {
case 'nick':
$addtoquery .= "`nickname` LIKE '%$search%' OR `akanick` LIKE
'%$search%'";
break;
case 'real':
$addtoquery .= "`fname` LIKE '%$search%' OR `lname` LIKE
'%$search%'";
break;
case 'email':
$addtoquery .= "`email` LIKE '%$search%'";
break;
case 'icq':
$addtoquery .= "`icq` LIKE '%$search%'";
break;
case 'aim':
$addtoquery .= "`aim` LIKE '%$search%'";
break;
case 'msn':
$addtoquery .= "`msn` LIKE '%$search%'";
break;
case 'yim':
$addtoquery .= "`yim` LIKE '%$search%'";
break;
}
} // end for - fields builder
The accompanying part of the form looks like this (don't ask why this is
done with a for loop, guess we had about those when I did it):
<td align="left" valign="top">Search in:<br>
<select name="fields[]" id="fields" size="4" multiple>
<?php
$fieldarray =
array('nick','real','email','icq','aim','msn','yim');
$fieldnames = array('Nickname','Real
name','Email','ICQ','AIM','MSN','YIM');
for ($i=0; $i < count($fieldarray); $i++) {
echo('<option value="'.$fieldarray[$i].'"');
if (! empty($_POST['fields'])) {
foreach($_POST['fields'] as $field) {
if ($fieldarray[$i] == $field) {
echo(' selected');
}
}
} else if ($fieldarray[$i] == 'nick') {
echo(' selected');
}
echo('>'.$fieldnames[$i]);
}
?>
</select></td>
FWIW
Rene
At 09:21 31-10-2004, Andy B wrote:
Sorry that doesn't do me a huge bit of good since I have no clue how to
write java in the first place. Does anybody know where I can find or get an
example of php code that shows how to get all the selected items from a
multiselect listbox and loop through them printing them on the screen??
--
Rene Brehmer
aka Metalbunny
If your life was a dream, would you wake up from a nightmare, dripping of
sweat, hoping it was over? Or would you wake up happy and pleased, ready to
take on the day with a smile?
http://metalbunny.net/
References, tools, and other useful stuff...
Check out the new Metalbunny forums at http://forums.metalbunny.net/
--- End Message ---
--- Begin Message ---
Would be easier if you didn't send it as HTML ... bad boy you
Rene
At 10:00 31-10-2004, M. Sokolewicz wrote:
---------[ input.html ]----------
.... one two three ....
---------[ ]----------
---------[ input.php ]----------
<?php
print_r($_POST);
?>
---------[ ]----------
---------[ output ]----------
Array
(
[select] => Array
(
[0] => 1
[1] => 2
)
[submit] => submit
)
---------[ ]----------
Above output is with #1 and #2 selected, and #3 not selected. Easy, huh?
- Tul
--
Rene Brehmer
aka Metalbunny
If your life was a dream, would you wake up from a nightmare, dripping of
sweat, hoping it was over? Or would you wake up happy and pleased, ready to
take on the day with a smile?
http://metalbunny.net/
References, tools, and other useful stuff...
Check out the new Metalbunny forums at http://forums.metalbunny.net/
--- End Message ---
--- Begin Message ---
> where did you place your php.ini?
In the root of my application in www. /home/mydomaine/www
Thanks,
Christian,
--- End Message ---
--- Begin Message ---
hello all
I am foreach()ing through an array of ip addresses in a 'ban script' and
have the following php code:
foreach($ips as $ip) {
preg_match("/$ip/", $_SERVER[REMOTE_ADDR]);
$ban = TRUE;
}
This is great, but if 127.0.0 were in the ban list (for example) it
would still produce a ban as it partially matches.
How can I alter the above so that only *exact* matches are banned?
Much thanks!
--
Nick W
--- End Message ---
--- Begin Message ---
Nick Wilson wrote:
> hello all
>
> I am foreach()ing through an array of ip addresses in a 'ban script' and
> have the following php code:
>
> foreach($ips as $ip) {
> preg_match("/$ip/", $_SERVER[REMOTE_ADDR]);
> $ban = TRUE;
> }
>
> This is great, but if 127.0.0 were in the ban list (for example) it
> would still produce a ban as it partially matches.
>
> How can I alter the above so that only *exact* matches are banned?
If I've understood your question right:
foreach($ips as $ip) {
preg_match("/^$ip$/", $_SERVER[REMOTE_ADDR]);
$ban = TRUE;
}
--
Per Jessen, Zurich
Let your spam stop here -- http://www.spamchek.com
--- End Message ---
--- Begin Message ---
Nick Wilson wrote:
How can I alter the above so that only *exact* matches are banned?
Using ^ and $ to mark the begin and end of the line. So try this
"/^$ip\$/"
--
Bye, K <http://www.ailis.de/~k/> (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9 53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)
signature.asc
Description: OpenPGP digital signature
--- End Message ---
--- Begin Message ---
I cannot fathom why you would use preg_match for this.
This will get an "exact match"...
if ($ip == $_SERVER[REMOTE_ADDR]) { $ban = true; }
Despite this being the worst idea I've ever seen, combined with a true lack
of understanding, I wish you well.
"Nick Wilson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> hello all
>
> I am foreach()ing through an array of ip addresses in a 'ban script' and
> have the following php code:
>
> foreach($ips as $ip) {
> preg_match("/$ip/", $_SERVER[REMOTE_ADDR]);
> $ban = TRUE;
> }
>
> This is great, but if 127.0.0 were in the ban list (for example) it
> would still produce a ban as it partially matches.
>
> How can I alter the above so that only *exact* matches are banned?
>
> Much thanks!
> --
> Nick W
--- End Message ---
--- Begin Message ---
Nick Wilson wrote:
hello all
I am foreach()ing through an array of ip addresses in a 'ban script' and
have the following php code:
foreach($ips as $ip) {
preg_match("/$ip/", $_SERVER[REMOTE_ADDR]);
$ban = TRUE;
}
This is great, but if 127.0.0 were in the ban list (for example) it
would still produce a ban as it partially matches.
How can I alter the above so that only *exact* matches are banned?
Much thanks!
I'd rather go with something like this:
$banned_ips = array('123.123.123.123', '321.321.321.321'); // Banned IPs
if (in_array($_SERVER['REMOTE_ADDR'], $banned_ips)) {
die('Dude, you\'re banned!');
}
But if I were you I'd choose something more advanced.
--
Daniel Schierbeck
Help spread Firefox (www.getfirefox.com):
http://www.spreadfirefox.com/?q=user/register&r=6584
--- End Message ---
--- Begin Message ---
Daniel Schierbeck wrote:
Nick Wilson wrote:
hello all
I am foreach()ing through an array of ip addresses in a 'ban script' and
have the following php code:
foreach($ips as $ip) {
preg_match("/$ip/", $_SERVER[REMOTE_ADDR]);
$ban = TRUE;
}
This is great, but if 127.0.0 were in the ban list (for example) it
would still produce a ban as it partially matches.
How can I alter the above so that only *exact* matches are banned?
Much thanks!
I'd rather go with something like this:
$banned_ips = array('123.123.123.123', '321.321.321.321'); // Banned IPs
if (in_array($_SERVER['REMOTE_ADDR'], $banned_ips)) {
die('Dude, you\'re banned!');
}
But if I were you I'd choose something more advanced.
And yes, I'm aware of the fact that 321.321.321.321 isn't a valid IP...
--
Daniel Schierbeck
Help spread Firefox (www.getfirefox.com):
http://www.spreadfirefox.com/?q=user/register&r=6584
--- End Message ---
--- Begin Message ---
* and then Aidan Lister declared....
> I cannot fathom why you would use preg_match for this.
>
> This will get an "exact match"...
> if ($ip == $_SERVER[REMOTE_ADDR]) { $ban = true; }
Ahh.. an oversight. The script has been cobbled together from a previous
version that supported partial matches. I'd just missed the obvious,
thankyou ;-)
> Despite this being the worst idea I've ever seen, combined with a true lack
> of understanding, I wish you well.
There is no need to be insulting. I doubt very much anyone thinks your a
clever guy for acting like a twat on a mailing list.
--
Nick W
--- End Message ---
--- Begin Message ---
* and then Per Jessen declared....
> foreach($ips as $ip) {
> preg_match("/^$ip$/", $_SERVER[REMOTE_ADDR]);
> $ban = TRUE;
> }
Great! - found a more sutable way but that's appreciated. Cheers!
--
Nick W
--- End Message ---
--- Begin Message ---
* and then Daniel Schierbeck declared....
> I'd rather go with something like this:
>
> $banned_ips = array('123.123.123.123', '321.321.321.321'); // Banned IPs
>
> if (in_array($_SERVER['REMOTE_ADDR'], $banned_ips)) {
> die('Dude, you\'re banned!');
> }
>
> But if I were you I'd choose something more advanced.
I think in_array() sounds like a great solution, wonder if it's faster
than comparing each ooe with == ? thanks!
--
Nick W
--- End Message ---
--- Begin Message ---
On Sun, 31 Oct 2004 12:58:04 +0100, Nick Wilson <[EMAIL PROTECTED]> wrote:
> I think in_array() sounds like a great solution, wonder if it's faster
> than comparing each ooe with == ? thanks!
Benchmark it both ways and find out. Then post back and tell us. :)
--
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/
--- End Message ---
--- Begin Message ---
* and then Greg Donald declared....
> On Sun, 31 Oct 2004 12:58:04 +0100, Nick Wilson <[EMAIL PROTECTED]> wrote:
> > I think in_array() sounds like a great solution, wonder if it's faster
> > than comparing each ooe with == ? thanks!
>
> Benchmark it both ways and find out. Then post back and tell us. :)
Started to, but found I cant ;(
I need to get the key from the array also (for use in a corresponding
array) and with in_array() I couldnt find a way to do it. So, im just
using == which is lightning fast anyway so no worries :)
thanks again..
--
Nick W
--- End Message ---
--- Begin Message ---
I need to run a query using PHP/MYSQL. The query should be for a week.
So if today is tuesday, the query should be from Monday to Sunday.
How in in php I can know when the beginning and end of the week?
TH
--- End Message ---
--- Begin Message ---
Hi Jerry,
I dunno if i got what you want to do... But
i would say :
1. Set a number to each day of the week (0 = sunday, 1 = monday, 6 =
saturday)
2. Get the date of today, so you can get the number of the day : $noDay
3. Do you SQL request from ($noDay + 1) to ($noDay-1)
(just need to test if $noDay > 6, then you loop it to 0)
Seb
Jerry Swanson wrote:
I need to run a query using PHP/MYSQL. The query should be for a week.
So if today is tuesday, the query should be from Monday to Sunday.
How in in php I can know when the beginning and end of the week?
TH
--- End Message ---
--- Begin Message ---
On Sun, 31 Oct 2004 00:19:12 -0400, Steven James Samuel Stapleton
<[EMAIL PROTECTED]> wrote:
> Relevant information:
> Windows XP Pro SP2
> PHP 5.0.2
> MySQL 4.0.21-nt
> command line (not server-side)
>
> mysql_select_db returns no errors, and does not result in a mysql_error(),
> however, later queries result in errors suggesting that the switch failed:
No errors, that's correct, but it does return a boolean value. So are
you testing that return value?
if( mysql_select_db('foo') !== true ) die('cannot select db');
> //I'm having problems with mysql_select_db("DBNAME", resource) and
> $test = mysql_query("use DBNAME", $resource);
You might want to try killing it right there with something like:
$test = mysql_query() || die('bad query: ' . mysql_error());
> //This results in no errors (I checked to make sure a true value was
> returned,
mysql_query() returns a resource handler, not a boolean value.
> //and made sure mysql_errno() returned 0).
> if(!$test || mysql_errno())
> {
> die("Error selecting DB");
> }
>
> //next, I'll make a query:
> mysql_query("create table foo ( bar int, morebar int )", $resource);
> if(mysql_errno())
> {
> die(mysql_error());
> }
> //I get
> //No Database Selected
$test = mysql_query() || die('bad query: ' . mysql_error());
--
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/
--- End Message ---
--- Begin Message ---
On 30 Oct 2004 22:30:35 -0000, Matthew Weier O'Phinney
<[EMAIL PROTECTED]> wrote:
> I have difficulty believing retrieving an image from a database will
> have similar speed performance as simply grabbing it from the
> filesystem... and if you're seeing a need to cache images on the
> filesystem anyways, that's certainly already an argument against it.
Zend.com / Leon Atkinson benchmarked it.
http://www.zend.com/zend/trick/tricks-sept-2001.php
<snip>
Conclusions
Based on the test results, it seems that keeping files in a database
cuts performance by approximately a third. It's hard to accept this
penalty in light of any meager advantages offered by keeping the files
in the databases instead of in a directory.
</snip>
--
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/
--- End Message ---
--- Begin Message ---
Hi Sebastian
Apologies for the random email, I wonder if you can take a look at a PHP5
aggregation issue I've run into.
I've modified your aggregation/delegate example[1] trying to get it to work as
there appear to have been API changes since that was written.
Getting the method of the delegate object and invoking it seems fine, however it
doesn't seem to be able to interpret params. When my delegated object's method
is invoked, the $parameters arg appears to be ignored, although it correctly
exists as an array of args when it gets to __call().
I've tried various formats for the args to invoke(), but can't get it to work -
any ideas?
I've modified the __call method of my class to look like this:
function __call($methodName, $parameters)
{
$delegated = false;
foreach ($this->aDelegates as $delegate) {
$method = new ReflectionMethod(get_class($delegate), $methodName);
$delegated = true;
return $method->invoke($delegate, $parameters);
}
if (!$delegated) {
PEAR::raiseError('Problem aggregating object',
SGL_ERROR_INVALIDCALL, PEAR_ERROR_DIE);
}
}
function addDelegate($delegate)
{
$this->aDelegates[] = $delegate;
}
Am running
- winXP
- PHP 5.02
- apache 2.052
thanks in advance,
Demian Turner
[1] http://www.zend.com/zend/php5/php5-delegation.php
--- End Message ---
--- Begin Message ---
I am trying to validate an XML document, using
DomDocument::schemaValidate() as in the following code:
<?php
$txt =<<<EOT
<?xml version="1.0"?>
<Article xmlns='http://www.example.com/xml'>
<Item>ItemText</Item>
</Article>
EOT;
$dom = new DOMDocument();
$dom->loadXML($txt);
if ($dom->schemaValidate("Article.xsd")) {
print $dom->saveXML();
}
?>
The schema I am trying to validate against is:
<?xml version="1.0" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="Article">
<xs:complexType>
<xs:sequence>
<xs:element name="Item" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
This produces the following output:
Warning: Element Article not declared in E:\PHPTest\testXML.php on line 10
Warning: Element Article not declared in E:\PHPTest\testXML.php on line 10
If I remove the default namespace from the article tag, the XML
validates correctly. I seem to recollect that namespace support is not
fully implemented, so my question is, is this a bug, or just something
not yet implemented, or is there an obvious blunder in what I am trying
to do, which I cannot see.
Best regards. . . Dusty
--- End Message ---
--- Begin Message ---
I've been looking around in the php documentation for a couple of hours
now but can't seem to find any functions to open a url in the current
browser window. Does php allow this? If so, could someone point me to a
link?
Basically what I'm trying to do is loop back in a login form until a
user enters a valid username/password and then redirect to that user's
personal info page.
Thanks for any help
Ken
--- End Message ---