php-general Digest 21 Oct 2010 00:47:17 -0000 Issue 6998
Topics (messages 308883 through 308901):
Re: Possible foreach bug; seeking advice to isolate the problem
308883 by: Gary
308884 by: Jonathan Sachs
308891 by: David Harkness
308893 by: Tommy Pham
308895 by: David Harkness
Weird Behavior
308885 by: Don Wieland
308886 by: Daniel Brown
308887 by: Alexander Schrijver
308888 by: Steven Buehler
308894 by: admin.buskirkgraphics.com
Calendar Logic Help
308889 by: Floyd Resler
308890 by: Tommy Pham
308892 by: Floyd Resler
Returning results
308896 by: David McGlone
308898 by: Bastien
308900 by: Daniel P. Brown
Independent Contractor Suggestions
308897 by: musicdev.gmail.com
308899 by: Jason Pruim
308901 by: Kris Craig
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 ---
Tommy Pham wrote:
>> -----Original Message-----
>> From: Gary
>> I can tell you how to solve it:
>> $a = array('a', 'b','c');
>> foreach($a as &$row){
>> //you don't have to do anything here
>> }
>> unset($row); // <----<<< THIS IS KEY!
>
> Shouldn't that be $row = null since unset will remove the last value,
> not just removing the variable also, from the array whereas the $row =
> null will tell the reference pointer that it doesn't point to a value.
,----[ http://php.net/manual/en/control-structures.foreach.php ]
| ,----[ code ]
| | <?php
| | $arr = array(1, 2, 3, 4);
| | foreach ($arr as &$value) {
| | $value = $value * 2;
| | }
| | // $arr is now array(2, 4, 6, 8)
| | unset($value); // break the reference with the last element
| | ?>
| `----
| ...
| Warning
|
| Reference of a $value and the last array element remain even after the
| foreach loop. It is recommended to destroy it by unset().
`----
If it's wrong, please blame the people who wrote the manual :)
--- End Message ---
--- Begin Message ---
On Wed, 20 Oct 2010 08:37:55 +0200, [email protected] (Gary)
wrote:
>Better. I can tell you how to solve it:
> $a = array('a', 'b','c');
> foreach($a as &$row){
> //you don't have to do anything here
> }
> unset($row); // <----<<< THIS IS KEY!
> print_r($a);
> foreach($a as $row){
> echo "<br />".$row;
> }
> print_r($a);
I don't quite I follow this. I'll have to try it when I have time (I
hope later today) to understand what you're proposing.
Unfortunately it won't work in this, for one or two reasons.
The first possible reason is that I'm not referencing the "as"
variable with an ampersand. If I'd have to add one to fix this
problem, it might cause other problems.
The second (definite) reason is that I can't read the array
destructively (with an unset). The problem occurs in code that is
preparing the array for later read-only use, so that would be
self-defeating!
--- End Message ---
--- Begin Message ---
On Wed, Oct 20, 2010 at 5:00 AM, Tommy Pham <[email protected]> wrote:
> Shouldn't that be $row = null since unset will remove the last value, not
> just removing the variable also, from the array whereas the $row = null
> will
> tell the reference pointer that it doesn't point to a value.
>
No, that would assign null to the last array element. References allow you
to assign any value--including null--to the container they reference.
Unsetting a reference breaks the reference without affecting whatever it
references.
$x = 5;
$y = &$x;
$y = null;
print_r($x);
var_dump($x);
--> NULL
David
--- End Message ---
--- Begin Message ---
On Wed, Oct 20, 2010 at 10:44 AM, David Harkness
<[email protected]> wrote:
> On Wed, Oct 20, 2010 at 5:00 AM, Tommy Pham <[email protected]> wrote:
>>
>> Shouldn't that be $row = null since unset will remove the last value, not
>> just removing the variable also, from the array whereas the $row = null
>> will
>> tell the reference pointer that it doesn't point to a value.
>
> No, that would assign null to the last array element. References allow you
> to assign any value--including null--to the container they reference.
> Unsetting a reference breaks the reference without affecting whatever it
> references.
>
> $x = 5;
> $y = &$x;
> $y = null;
> print_r($x);
> var_dump($x);
>
> --> NULL
>
> David
>
hmm.. About 8-9 years ago I did a project where I used the reference
in a foreach loop as the OP. unset not only remove the variable but
also the value in the array. I tried several methods at that time and
ended up assigning null to get what I wanted without modifying the
array. I'll have to dig up that project later to see.
Thanks,
Tommy
--- End Message ---
--- Begin Message ---
On Wed, Oct 20, 2010 at 11:08 AM, Tommy Pham <[email protected]> wrote:
> hmm.. About 8-9 years ago I did a project where I used the reference
> in a foreach loop as the OP. unset not only remove the variable but
> also the value in the array. I tried several methods at that time and
> ended up assigning null to get what I wanted without modifying the
> array. I'll have to dig up that project later to see.
>
To be thorough, I ran the same test as above using unset(), and it correctly
clears the reference and leaves $x in tact.
$x = 5;
$y = &$x;
unset($y);
var_dump($x);
--> 5
var_dump($y);
--> NULL
It's quite possible this behavior was changed along the way. I started using
PHP last year with 5.2.
David
--- End Message ---
--- Begin Message ---
Little help please ;)
$CD = 1287583899
$q1s = 1283313600
$q1e = 1291093200
$q2s = 1291179600
$q2e = 1298869200
$q3s = 1298955600
$q3e = 1306814400
$q4s = 1306900800
$q4e = 1314763200
Why does the following not return the value "1" in the $qCur var
// Current Quarter
if($CD >= $q1s && $CD <= $q1e) $qCur = 1;
if($CD >= $q2s && $CD <= $q2e) $qCur = 2;
if($CD >= $q3s && $CD <= $q3e) $qCur = 3;
if($CD >= $q4s && $CD <= $q4e) $qCur = 4;
it returns "4"
Don Wieland
--- End Message ---
--- Begin Message ---
On Wed, Oct 20, 2010 at 10:35, Don Wieland <[email protected]> wrote:
> Little help please ;)
>
> $CD = 1287583899
> $q1s = 1283313600
> $q1e = 1291093200
> $q2s = 1291179600
> $q2e = 1298869200
> $q3s = 1298955600
> $q3e = 1306814400
> $q4s = 1306900800
> $q4e = 1314763200
>
> Why does the following not return the value "1" in the $qCur var
>
> // Current Quarter
> if($CD >= $q1s && $CD <= $q1e) $qCur = 1;
> if($CD >= $q2s && $CD <= $q2e) $qCur = 2;
> if($CD >= $q3s && $CD <= $q3e) $qCur = 3;
> if($CD >= $q4s && $CD <= $q4e) $qCur = 4;
>
> it returns "4"
That will return 1 if you add semicolons to the end of your
variable definition block lines. Otherwise you'll get an unexpected
T_VARIABLE error.
In fact, I just tested it and it returned 1 as expected.
--
</Daniel P. Brown>
Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/
--- End Message ---
--- Begin Message ---
On Wed, Oct 20, 2010 at 07:35:26AM -0700, Don Wieland wrote:
> Little help please ;)
>
> $CD = 1287583899
> $q1s = 1283313600
> $q1e = 1291093200
> $q2s = 1291179600
> $q2e = 1298869200
> $q3s = 1298955600
> $q3e = 1306814400
> $q4s = 1306900800
> $q4e = 1314763200
>
> Why does the following not return the value "1" in the $qCur var
>
> // Current Quarter
> if($CD >= $q1s && $CD <= $q1e) $qCur = 1;
> if($CD >= $q2s && $CD <= $q2e) $qCur = 2;
> if($CD >= $q3s && $CD <= $q3e) $qCur = 3;
> if($CD >= $q4s && $CD <= $q4e) $qCur = 4;
>
> it returns "4"
No, $qCur is set to 1.
You've forgot the semicolons if you're testing with this.
--- End Message ---
--- Begin Message ---
it returns 1 for me. Did you put the simicolon after the values?
$CD = 1287583899;
$q1s = 1283313600;
$q1e = 1291093200;
$q2s = 1291179600;
$q2e = 1298869200;
$q3s = 1298955600;
$q3e = 1306814400;
$q4s = 1306900800;
$q4e = 1314763200;
-----Original Message-----
From: Don Wieland [mailto:[email protected]]
Sent: Wednesday, October 20, 2010 9:35 AM
To: [email protected]
Subject: [PHP] Weird Behavior
Little help please ;)
$CD = 1287583899
$q1s = 1283313600
$q1e = 1291093200
$q2s = 1291179600
$q2e = 1298869200
$q3s = 1298955600
$q3e = 1306814400
$q4s = 1306900800
$q4e = 1314763200
Why does the following not return the value "1" in the $qCur var
// Current Quarter
if($CD >= $q1s && $CD <= $q1e) $qCur = 1;
if($CD >= $q2s && $CD <= $q2e) $qCur = 2;
if($CD >= $q3s && $CD <= $q3e) $qCur = 3;
if($CD >= $q4s && $CD <= $q4e) $qCur = 4;
it returns "4"
Don Wieland
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Hmmmmm
I guess the little person inside, just hates the long way of doing
something.
My suggestion
$CD = 1287583899;
$q1s = 1283313600;
$q1e = 1291093200;
$q2s = 1291179600;
$q2e = 1298869200;
$q3s = 1298955600;
$q3e = 1306814400;
$q4s = 1306900800;
$q4e = 1314763200;
for($a=1; $a<=4; $a++)
{
$sSQ = "q".$a."s";
$eSQ = "q".$a."e";
if(($CD >= $$sSQ) && ($CD <= $$eSQ)){ $qCUR = "$a";}
}
echo $qCUR;
The result is 1
Richard L. Buskirk
-----Original Message-----
From: Don Wieland [mailto:[email protected]]
Sent: Wednesday, October 20, 2010 10:35 AM
To: [email protected]
Subject: [PHP] Weird Behavior
Little help please ;)
$CD = 1287583899
$q1s = 1283313600
$q1e = 1291093200
$q2s = 1291179600
$q2e = 1298869200
$q3s = 1298955600
$q3e = 1306814400
$q4s = 1306900800
$q4e = 1314763200
Why does the following not return the value "1" in the $qCur var
// Current Quarter
if($CD >= $q1s && $CD <= $q1e) $qCur = 1;
if($CD >= $q2s && $CD <= $q2e) $qCur = 2;
if($CD >= $q3s && $CD <= $q3e) $qCur = 3;
if($CD >= $q4s && $CD <= $q4e) $qCur = 4;
it returns "4"
Don Wieland
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
I'm having problems getting my head around some login for a calendar.
Specifically, the problem is drawing weekly views for events that span multiple
days. I've gotten it so that if an event starts in the week being viewed, the
days draw correctly for the remainder of the week. However, if the event goes
into the next week, its start date is now outside my date range and so it
doesn't display. I know how to say the logic, I'm not sure how to write it!
The logic would be: if any date between the start and end dates of the event
are within the week being displayed, show the event. I'd like to put the logic
into my MySQL query so I don't have to get all events from the calendar to see
what should be displayed. Any ideas?
Thanks!
Floyd
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Floyd Resler [mailto:[email protected]]
> Sent: Wednesday, October 20, 2010 9:17 AM
> To: PHP
> Subject: [PHP] Calendar Logic Help
>
> I'm having problems getting my head around some login for a calendar.
> Specifically, the problem is drawing weekly views for events that span
> multiple days. I've gotten it so that if an event starts in the week
being
> viewed, the days draw correctly for the remainder of the week. However,
if
> the event goes into the next week, its start date is now outside my date
> range and so it doesn't display. I know how to say the logic, I'm not
sure
> how to write it! The logic would be: if any date between the start and
end
> dates of the event are within the week being displayed, show the event.
I'd
> like to put the logic into my MySQL query so I don't have to get all
events
> from the calendar to see what should be displayed. Any ideas?
>
> Thanks!
> Floyd
>
It's hard to give you hints without knowing some actual PHP code and SQL
table columns but here goes:
PHP logic: $event['startDate'] <= $weekEnd && $event['endDate'] >=
$weekStart
Query logic: SELECT * FROM event_table WHERE `start_date` <= @weekEnd and
`end_date` >= @weekStart
week* is the week being viewed. You may have to use the DateTime class or
one of the date_* functions to compare the date for the PHP logic. @ is the
input query parameter. This assumes you have table columns for the event:
start_date & end_date. Adjust the query as needed for multi table joins.
Regards,
Tommy
--- End Message ---
--- Begin Message ---
On Oct 20, 2010, at 12:47 PM, Tommy Pham wrote:
>> -----Original Message-----
>> From: Floyd Resler [mailto:[email protected]]
>> Sent: Wednesday, October 20, 2010 9:17 AM
>> To: PHP
>> Subject: [PHP] Calendar Logic Help
>>
>> I'm having problems getting my head around some login for a calendar.
>> Specifically, the problem is drawing weekly views for events that span
>> multiple days. I've gotten it so that if an event starts in the week
> being
>> viewed, the days draw correctly for the remainder of the week. However,
> if
>> the event goes into the next week, its start date is now outside my date
>> range and so it doesn't display. I know how to say the logic, I'm not
> sure
>> how to write it! The logic would be: if any date between the start and
> end
>> dates of the event are within the week being displayed, show the event.
> I'd
>> like to put the logic into my MySQL query so I don't have to get all
> events
>> from the calendar to see what should be displayed. Any ideas?
>>
>> Thanks!
>> Floyd
>>
>
> It's hard to give you hints without knowing some actual PHP code and SQL
> table columns but here goes:
>
> PHP logic: $event['startDate'] <= $weekEnd && $event['endDate'] >=
> $weekStart
>
> Query logic: SELECT * FROM event_table WHERE `start_date` <= @weekEnd and
> `end_date` >= @weekStart
>
> week* is the week being viewed. You may have to use the DateTime class or
> one of the date_* functions to compare the date for the PHP logic. @ is the
> input query parameter. This assumes you have table columns for the event:
> start_date & end_date. Adjust the query as needed for multi table joins.
>
> Regards,
> Tommy
>
That worked perfect!
Thanks!
Floyd
--- End Message ---
--- Begin Message ---
Hi everyone, it's me again :-/
I'm having a whole lot of trouble figuring out how to return a result
from a query such as in this code example:
function LearnIt(){
$query = "SELECT learn_id FROM mydatabase ";
$result = mysql_query($query);
return $result;
}
I already achieved a connection to the database with no problem, to
verify I wrote this query also:
function GetMeARow(){
$query = "SELECT learn_id FROM mydatabase ";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
echo $row[learn_id];
}
With the latter, It works as expected, echoing the 2 rows I have in the
DB, but I'm trying to understand the method used in the former.
--
Blessings
David M.
--- End Message ---
--- Begin Message ---
On 2010-10-20, at 7:59 PM, David McGlone <[email protected]> wrote:
> Hi everyone, it's me again :-/
>
> I'm having a whole lot of trouble figuring out how to return a result
> from a query such as in this code example:
>
> function LearnIt(){
> $query = "SELECT learn_id FROM mydatabase ";
> $result = mysql_query($query);
> return $result;
> }
>
> I already achieved a connection to the database with no problem, to
> verify I wrote this query also:
>
> function GetMeARow(){
>
> $query = "SELECT learn_id FROM mydatabase ";
> $result = mysql_query($query);
> while($row = mysql_fetch_array($result)){
> echo $row[learn_id];
> }
>
> With the latter, It works as expected, echoing the 2 rows I have in the
> DB, but I'm trying to understand the method used in the former.
>
> --
> Blessings
> David M.
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
David, the $result variable/object is the handle to the result data set, not
the resulting data. You would still need to access the data set via the Mysql_*
set of functions like Mysql-fetch_array or Mysql_result like you did in the
second example
Bastien Koert
>
--- End Message ---
--- Begin Message ---
On Wed, Oct 20, 2010 at 20:11, Bastien <[email protected]> wrote:
>
> David, the $result variable/object is the handle to the result data set, not
> the resulting data. You would still need to access the data set via the
> Mysql_* set of functions like Mysql-fetch_array or Mysql_result like you did
> in the second example
Must've been typing from the iPhone here. ;-P
--
</Daniel P. Brown>
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/
--- End Message ---
--- Begin Message ---
Hi List,
I'm currently working on a medium sized project as an independent contractor.
The project is reaching the 2000 hour range and the client has asked for a
project cost. The problem I have in providing the client with a proper
estimate is that the client is a start-up and does not have the dollar amount
the project will actually cost (@ an average of $20 per/h the cost is roughly
$40,000, quite cheap in my opinion considering the project size and required
functionality: logins, cms, mysql, ssl, payment systems, shopping cart, and
functionality specific to the user type).
I wanted to gain some suggestions on alternative methods of making the project
cost reachable to the client, while also allowing me to make a profit. An idea
that sounded very good was to agree with the client on a minimal system and
upon delivery allow them to place a cost on what they receive. The problem I
have with this idea is that I'm afraid the client might not be fair in costing
the delivered system.
If you are an independent contractor, what methods have you used and what would
you suggest? Greatly appreciate any response.
My apologies in advance if this is not the place to ask.
Thanks.
--- End Message ---
--- Begin Message ---
On Oct 20, 2010, at 8:08 PM, <[email protected]> wrote:
Hi List,
I'm currently working on a medium sized project as an independent
contractor. The project is reaching the 2000 hour range and the
client has asked for a project cost. The problem I have in
providing the client with a proper estimate is that the client is a
start-up and does not have the dollar amount the project will
actually cost (@ an average of $20 per/h the cost is roughly
$40,000, quite cheap in my opinion considering the project size and
required functionality: logins, cms, mysql, ssl, payment systems,
shopping cart, and functionality specific to the user type).
I wanted to gain some suggestions on alternative methods of making
the project cost reachable to the client, while also allowing me to
make a profit. An idea that sounded very good was to agree with the
client on a minimal system and upon delivery allow them to place a
cost on what they receive. The problem I have with this idea is
that I'm afraid the client might not be fair in costing the
delivered system.
If you are an independent contractor, what methods have you used and
what would you suggest? Greatly appreciate any response.
My apologies in advance if this is not the place to ask.
Thanks.
Hi,
I've never worked on anything that large so keep that in mind... What
comes to mind though is to do it like a module system... Simply
provide the most basic part of it first at a price of $5700 ($40,000 /
7 logins, cms, mysql,ssl,payment, shopping, user specifics)
and when they decide they want to be able to take credit cards over
the website sell them the "payment systems" module.
It also gives you a product that if it is something that can be used
in the general market you can market it and sell it to others.
Just my 2¢ :)
Jason Pruim
--- End Message ---
--- Begin Message ---
Hi musicdev,
There are a couple issues I think need to be addressed with what youd
described. First and foremost, $20/hr is considerably below the going
rate for PHP work, especially for projects as large as the one you're
talking about.
I used to do freelance PHP work for about 5 years before I went to
work for Microsoft, and when I originally started I was just charging
about 20 bucks an hour as well. It proved to be a disaster. Contrary
to what common sense might tell you, I've found that lower-budget
clients always produce the most drama, are the most demanding, and
least reliable when it comes to paying the invoices on-time.
Furthermore, larger clients will generally ignore you in favor of
developers who charge more, the mindset being that, if you're charging
such a low amount, the quality of your work probably isn't that good.
I did a lot better after I started charging $100/hr for my work. A
*lot* better! This was after my research showed that PHP development
firms generally charge a minimum of $80/hr for PHP work, and can go as
high as $200/hr. So if you're going at $20/hr, the companies with
deep pockets probably won't take you seriously, and the clients you do
get will be the ones who want a ton of work done but don't have the
budget available to make it worth your while. Those are the clients
who will take advantage of you if you're not careful.
With your specific dilemma, if you already quoted $20/hr then of
course you should honor that. However, I would strongly suggest that
you do *not* allow the client to
determine the cost of the deliverables after the work has already been
done. Nine times out of ten you will get taken advantage of, because
the client knows you already did the work which means they have all
the leverage. After all, ten cents on the dollar is better than zero,
right? You don't want to put yourself in that situation.
Instead, here's what I would suggest: Work with the client to
determine a bare minimum of work that would need to be done for the
"first phase." Based off the $20/hr you quoted, determine how many
hours that will take and give them a quote. Then, develop a statement
of work document (that both you and the client will have to sign) for
that phase, outlining specifically what work will be done and break it
up into deliverable pieces. Upon completion of each "chunk" of work,
a percentage of the total quote will be due. This ensures that you
get paid for your work and that the client receives the work s/he is
paying for. It also breaks-up the payment schedule so that it's a bit
easier on the client's budget. If the client runs out of money midway
through or whatever, you simply suspend work until they get more funds
and then resume where you left off. I've found this model to be the
most successful on projects like this.
I hope this helps. If you like, I'd be happy to email you a sample
copy of the SOW/contract I've used with past clients.
--Kris
--- End Message ---