php-general Digest 3 May 2005 20:12:52 -0000 Issue 3433
Topics (messages 214371 through 214383):
Merging Strings
214371 by: Rolf van de Krol
214372 by: Jochem Maas
Re: setting condition problem
214373 by: Mark Rees
Re: handling a user pressing browser's back button
214374 by: Matthew Weier O'Phinney
Re: Can someone help me build a regular expression?
214375 by: Matthew Weier O'Phinney
Check for doubleposts
214376 by: Fredrik Arild Takle
214378 by: pete M
Error suppression operator (@)
214377 by: GamblerZG
214382 by: Jason Barnett
Valid email address syntax script?
214379 by: JM
214380 by: Matthew Weier O'Phinney
Access files
214381 by: Don
Re: forms
214383 by: Jason Barnett
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 ---
Hi all,
why do result the following two examples in two different value for $month?
(1)
$current_date = getdate(time());
$month = strval($current_date['year']);
$month .= (strlen(strval($current_date['mon'])) ==
2)?$current_date['mon']:("0".$current_date['mon']);
(2)
$current_date = getdate(time());
$month = strval($current_date['year']) .
(strlen(strval($current_date['mon'])) ==
2)?$current_date['mon']:("0".$current_date['mon']);
The first example sets $month to 200505 and the second sets it to 5. Why is
that. In my opinion they both should set it to 200505.
Is this a weird bug, or did i something wrong?
I'm using PHP 4.3.10 with Apache 1.3.33 on W2K Pro, but the server of my
hosting provider does the same (php 4.3.10 + apache (don't know the version,
i guess 1.3.33) on linux (i'm not sure, but i thought it was redhat)).
Rolf van de Krol
--- End Message ---
--- Begin Message ---
Rolf van de Krol wrote:
Hi all,
why do result the following two examples in two different value for $month?
(1)
$current_date = getdate(time());
$month = strval($current_date['year']);
$month .= (strlen(strval($current_date['mon'])) == 2)
? $current_date['mon']
: ("0".$current_date['mon']);
$current_date = getdate(time());
$month = strval($current_date['year']) . (strlen(strval($current_date['mon'])) == 2) ?
$current_date['mon']
: ("0".$current_date['mon']);
in the second version:
strval($current_date['year']) . (strlen(strval($current_date['mon'])) == 2)
is equal to TRUE, therefore $current_date['mon'] is returned, you are missing
parentheses around the tertiary expression (?:).... so:
$current_date = getdate(time());
$month = strval($current_date['year']) .
((strlen(strval($current_date['mon'])) == 2) ? $current_date['mon'] :
"0".$current_date['mon']);
btw, have a look at str_pad:
$current_date = getdate();
$month = str_pad($current_date['mon'], 2, "0", STR_PAD_LEFT);
echo $month;
The first example sets $month to 200505 and the second sets it to 5. Why is
that. In my opinion they both should set it to 200505.
Is this a weird bug, or did i something wrong?
I'm using PHP 4.3.10 with Apache 1.3.33 on W2K Pro, but the server of my
hosting provider does the same (php 4.3.10 + apache (don't know the version,
i guess 1.3.33) on linux (i'm not sure, but i thought it was redhat)).
Rolf van de Krol
--- End Message ---
--- Begin Message ---
Does this help?
Select
*
From
Projects
Order By
Relate,Title
If not, please provide more details on the output you want to see and
the structure of your table
Mark
-----Original Message-----
From: Ahmed Abdel-Aliem [mailto:[EMAIL PROTECTED]
Sent: 02 May 2005 21:49
To: [email protected]
Subject: [PHP] setting condition problem
hi all
i have a query that grabs records from the database, it works fine,
but i have a problem with acondition i want to set for it
the variable $Record[Relate] has 1 of 2 values, "self" or "share"
what i wanna do is that when the variable has the value "share" it do
check the records grabbed and get the other records that has the value
share and $Record[Title] the same and display them once,
i don't know how to start doing this,
can anyone guide me or tell me how to do it
thanks in advance
here is the query
<?
$Query = "SELECT ID FROM projects";
$Result= mysql_query($Query);
$Total_Numbers = mysql_num_rows($Result);
$StartingID=$_GET['StartingID'];
$StartingID = ($StartingID) ? $StartingID : 0; //if rec is passed in,
use it,
$Row = array();
$Query = mysql_query("SELECT * FROM projects ORDER BY ID DESC LIMIT
$StartingID,$Items_Numbers");
$Num = mysql_num_rows($Query);
while ($Record=mysql_fetch_array($Query)){
$Record[ID] = stripslashes($Record[ID]);
$Record[User] = stripslashes($Record[User]);
$Record[Relate] = stripslashes($Record[Relate]);
$Record[Thumb] = stripslashes($Record[Thumb]);
$Record[Shot] = stripslashes($Record[Shot]);
$Record[Title] = stripslashes($Record[Title]);
$Record[Link] = stripslashes($Record[Link]);
$Record[Type] = stripslashes($Record[Type]);
$Record[Skill] = stripslashes($Record[Skill]);
$Record[Info] = stripslashes($Record[Info]);
$Record[Time] = stripslashes($Record[Time]);
$Record[Date] = stripslashes($Record[Date]);
$Record[Rate] = stripslashes($Record[Rate]);
$Record[Raters] = stripslashes($Record[Raters]);
$Row[] = $Record;
}
$Next = $StartingID+$Items_Numbers;
$Prev = $StartingID-$Items_Numbers;
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Gamma Global : Suppliers of HPCompaq, IBM, Acer, EPI, APC, Cyclades, D-Link,
Cisco, Sun Microsystems, 3Com
GAMMA GLOBAL (UK) LTD IS A RECOGNISED 'INVESTOR IN PEOPLE' AND AN 'ISO 9001
2000' REGISTERED COMPANY
**********************************************************************
CONFIDENTIALITY NOTICE:
This Email is confidential and may also be privileged. If you are not the
intended recipient, please notify the sender IMMEDIATELY; you should not
copy the email or use it for any purpose or disclose its contents to any
other person.
GENERAL STATEMENT:
Any statements made, or intentions expressed in this communication may not
necessarily reflect the view of Gamma Global (UK) Ltd. Be advised that no
content
herein may be held binding upon Gamma Global (UK) Ltd or any associated company
unless confirmed by the issuance of a formal contractual document or
Purchase Order, subject to our Terms and Conditions available from
http://www.gammaglobal.com
E&OE
**********************************************************************
**********************************************************************
--- End Message ---
--- Begin Message ---
* James <[EMAIL PROTECTED]>:
> Actually:
>
> Will there be an issue with the back button if I use 1 script to do
> all of what I posted before?
No.
> Thank you guys for the answers. I think I will go with the following
> approach.
>
> (A) script 1 submits to script 2 then
> (B) script 2 redirects browser back to script 1
>
> Script 1 is in charge of submitting and displaying; script 2 does the
> processing.
>
> This list is the best!
> -James
>
>
> At 2:08 AM +0000 4/27/05, Matthew Weier O'Phinney wrote:
> >* James <[EMAIL PROTECTED]>:
>>> I apologize in advance if I'm asking basic questions...
>>>
>>> When you hit the back button, won't the browser just take the page
>>> from the cache?
>>>
>>> I haven't switched my POSTs to GETs and this is what I'm seeing.
>>> I have a list of images. There are check boxes next to the images.
>>> When the user checks images and clicks on a DELETE CHECKED link, a
>>> new list is shown (minus the ones deleted.) When the user hits the
>>> BACK button, I see the list again with checks next to the previous
>>> images marked for deletion
> >
> >By the way... the rule of thumb I think about is this:
> >* Use GET requests when you want to be able to bookmark the page --
>> i.e., when you want the behaviour repeatable. Typical example is
>> searches.
> >
> >* Use POST requests when the operation will affect the data in some way
>> that shouldn't be cached. Examples: submitting data that will be
>> stored in the database, will update a database, or will delete an
>> entry in the database.
> >
> >Because of the back button issues (namely, not all browsers treat 'back'
> >the same way), you will need to do some workarounds, typically with
> >sessions; I've mentioned these under separate cover.
> >
>>> Just in case...
>>> I tried to add the following header before any html output to force
>>> the browser to not load from the cache and it didn't work.
>>>
>>> header("Cache-Control: no-store, no-cache, must-revalidate");
> >
> >Not all browsers will actually follow these 'rules' (actually, they're
> >in the HTTP specification, but 'rule' just sounds better). Heck,
> >versions of the same browser on different platforms sometimes treat them
> >differently.
> >
> >This is why session handling techniques are a common 'fix' for bad
> >browser behaviour in these instances.
> >
> >--
> >Matthew Weier O'Phinney | WEBSITES:
> >Webmaster and IT Specialist | http://www.garden.org
> >National Gardening Association | http://www.kidsgardening.com
> >802-863-5251 x156 | http://nationalgardenmonth.org
> >mailto:[EMAIL PROTECTED] | http://vermontbotanical.org
> >
> >--
> >PHP General Mailing List (http://www.php.net/)
> >To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Matthew Weier O'Phinney | WEBSITES:
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:[EMAIL PROTECTED] | http://vermontbotanical.org
--- End Message ---
--- Begin Message ---
* Rory Browne <[EMAIL PROTECTED]>:
> > You mite try this. I know that this work with perl.
> >
> > =~ m/^[0-9][A-Z][a-z]{2-3} \.[0-9]+$/
>
> I'm not sure what the initial m does(I'm not a perl person),
The 'm' is an optional flag indicating that a 'match' regexp (versus a
substitution or transliteration) follows. It's typically only necessary
in perl if using delimiters other than / around the regexp.
(The person who posted that should have written it as PHP to avoid
confusion: preg_match('/^[0-9][A-Z][a-z]{2-3} \.[0-9]+$/', $string);)
--
Matthew Weier O'Phinney | WEBSITES:
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:[EMAIL PROTECTED] | http://vermontbotanical.org
--- End Message ---
--- Begin Message ---
Hi,
what is the easiest way to check if a person i registered twice in a
mysql-table. Lets assume that I only check if the last name is in the table
more than once. This is in mysql 4.0 (subquery not an option).
Do I have to use arrays and in_array. Or is there a more elegant solution?
Best regards
Fredrik A. Takle
--- End Message ---
--- Begin Message ---
set a $_SESSION['var'] at the end of the first post and check for this
the second time around
pete
Fredrik Arild Takle wrote:
Hi,
what is the easiest way to check if a person i registered twice in a
mysql-table. Lets assume that I only check if the last name is in the table
more than once. This is in mysql 4.0 (subquery not an option).
Do I have to use arrays and in_array. Or is there a more elegant solution?
Best regards
Fredrik A. Takle
--- End Message ---
--- Begin Message ---
I would like to know, whether using @ is a good practice. For example, I
have an array of unknown length $array.
Is it all right write something like this:
@list($first, $second) = $array;
or is it better to do length check?
--- End Message ---
--- Begin Message ---
GamblerZG wrote:
I would like to know, whether using @ is a good practice. For example, I
have an array of unknown length $array.
Is it all right write something like this:
@list($first, $second) = $array;
or is it better to do length check?
Using @ is good practice in any case where you simply *don't care*
whether you had an error or not. So if your scripts don't need a value
stored in $first or in $second, then you can use the @ operator. But
don't use @ in any case where you need to trap for errors (e.g.
validating input from $_GET / $_POST).
--- End Message ---
--- Begin Message ---
Does anyone have a nice email address syntax checking script they'd
like to share? Regular expression-based anyone? TIA.
--
J
--- End Message ---
--- Begin Message ---
* Jm <[EMAIL PROTECTED]>:
> Does anyone have a nice email address syntax checking script they'd
> like to share? Regular expression-based anyone? TIA.
I use the following regex:
preg_match('/[EMAIL PROTECTED]@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email)
I believe I got it out of the PHP Cookbook, by David Sklar, but I can't
remember for certain. It's not 100% accurate, but I rarely have
complaints from users whose emails don't validate.
--
Matthew Weier O'Phinney | WEBSITES:
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:[EMAIL PROTECTED] | http://vermontbotanical.org
--- End Message ---
--- Begin Message ---
Hi,
I am using php 4.3.11 on a RedHat Linux server running Apache. I have a
requirement where I need to take a flat file containing formatted data and
produce an Access 97 MDB file.
Does anyone know of a class or library that will enable me to do this?
Thanks,
Don
--- End Message ---
--- Begin Message ---
Lisa A wrote:
Does anyone know of a good easy php script or Form that we can use with
Front Page.
We need a form to get results, that actually sends the results in a format
that is easy to read.
Not all run together with no spaces, etc. like the Front Page forms.
Thanks,
Lisa A
<?php
/** File Action.php
* This page should be the action for your form page
*/
/** Formatting */
echo '<pre>';
/** Print out form vars */
print_r($_GET);
print_r($_POST);
/** Not 100% accurate, but an alternative if you're lazy */
print_r($_REQUEST);
/** Just for completeness, the closing tag */
echo '</pre>';
?>
--- End Message ---