Re: [PHP] Re: Preferred Syntax

2011-12-17 Thread Ross McKay
On Fri, 16 Dec 2011 23:53:46 -0500, Eric Butera wrote:

>To all the people who responded to this thread:
>It is 2011 - please stop writing code like this.
>
>To the OP:
>I'm glad you're asking questions and realizing you're not happy with
>your current abilities and suspect there's a better way.  I've read
>the replies in this thread and feel a bit let down.  Use a templating
>language - yes, I understand that is what php is for - but I won't go
>into it.  You should not be echoing, printing, or any other method of
>concatenating html dealing with escaping quotes inside your php logic
>code.  Please separate your concerns.

By and large, I agree with you, and certainly it is a good idea to raise
that with the OP since they were asking about recommended practices.
However, "should not" is not the same as "don't" and there are still
places where this is appropriate. 

Here's a chunk of real code from a WordPress plugin, taken from the
class that extends the Page admin form to provide a button for selecting
a custom associated image:

echo <<

{$this->getAttachmentCaption($fieldValue)}


HTML;

HEREDOC provides me a way to do templating in a simple way within a
WordPress hook function. The purpose of the hook is to provide a way to
augment WordPress Page editing by adding some HTML; sending a small
fragment of HTML to the browser is its function. I gain nothing by
spinning that fragment out to a template file somewhere.

For other hook functions (e.g. representing shortcodes), it is
beneficial to use templating, and I do so -- but horses for courses.

>Not sure what that means?  That's OK!  If you want to move forward,
>look up how modern frameworks deal with this issue using their views
>or template views.  You don't have to use a framework if you do not
>want to, that's perfectly fine.  If it works, it works.  But in the
>end, it the separation of logic and html is essential to code
>maintenance.

Applause! :)
-- 
Ross McKay, Toronto, NSW Australia
"The chief cause of problems is solutions" -Eric Sevareid

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Working on a Subsummary Report

2011-12-17 Thread DealTek
>> 
> 
> for the above to work right, you will need to loop through the mysql result 
> set
> one time.  Placing all the results in to one large array.  Then you can loop
> through the array as many times as needed.
> 
> What you will probably find is that you can sort all the data into the proper
> order withing your SQL statement.  Then display the data looping through the
> mysql result set once without having to create the additional array mentioned 
> in
> my first statement above.



Thanks Jim,

I will look into how to make this work with arrays...

more beginner questions...

- as stated -  when I try to loop through 2x ...
- the table 2 only shows 1 record..
- Q: ... like the query number row number? needs to be reset - but how?

So is it not possible to loop more than 1x? Is that why we are loading into 
array?


--
Thanks,
Dave - DealTek
deal...@gmail.com
[db-11]




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] dealing with this code $_POST['custom´]

2011-12-17 Thread Stuart Dallas
On 17 Dec 2011, at 13:27, Marc Guay wrote:

> Just forwarding Carlos' response to the list...
> 
> 
> -- Forwarded message --
> From: Carlos Sura 
> Date: 17 December 2011 01:15
> Subject: Re: [PHP] dealing with this code $_POST['custom´]
> To: Marc Guay 
> 
> 
> 
> 
> On 16 December 2011 15:57, Marc Guay  wrote:
>> 
>>> $saving_list = $_POST['custom'] == 'FR' ? 148 : 147;
>> 
>> Hi there, here's a quick translatation of this code that might help
>> you understand it better:
>> 
>> if ($_POST['custom'] == 'FR'){
>>  $saving_list = 148;
>> }
>> else{
>>  $saving_list = 147;
>> }
> 
> 
> 
> Hello,
> 
> Thank you both for answer me.
> 
> Also I would like to thank you Marc Guay, because with your answer I
> figured out how to do it.
> 
> My code is like this:
> 
> //$saving_list = $_POST['custom'] == 'FR' ? 148 : 147;
>   if ($_POST['custom'] == 'FR'){
> $saving_list = 148;
>}
>   if ($_POST['custom'] == 'EN'){
> $saving_list = 147;
>}
>  else{
>  $saving_list = 152;
>  }
> 
> I'm not sure if that's the best way, but it is working for me as I
> expected, althought any other recommendation would be great.


In that case you haven't tested FR yet. FR will set it to 152, not 148. Try 
this...

if ($_POST['custom'] == 'FR') {
  $saving_list = 148;
} elseif ($_POST['custom'] == 'EN') {
  $saving_list = 147;
} else {
  $saving_list = 152;
}

Personally I'd recommend a switch for this type of logic...

switch ($_POST['custom']) {
  case 'FR':
$saving_list = 148;
break;
  case 'EN':
$saving_list = 147;
break;
  default:
$saving_list = 152;
}

However, given the simplicity of what you're doing, an array would be a lot 
more efficient...

$saving_list_options = array(
  'FR' => 148,
  'EN' => 147,
);
$saving_list = isset($saving_list_options[$_POST['custom']]) ? 
$saving_list_options[$_POST['custom']] : 152;

Thinking a little beyond that, is that list of options really hard coded or do 
they exist elsewhere (e.g. in a database)? If they do then you really should be 
getting the value from there.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Working on a Subsummary Report

2011-12-17 Thread DealTek

On Dec 16, 2011, at 12:56 PM, Jim Lucas wrote:
> 
> 
> 1) What does your db schema look like?
> 2) What SQL do you currently use?
> 3) What criteria do you want to use to sort the data?
> 4) Will the output be plaintext, html, etc?
> 5) Is this going to be used to import into another app, or display & printing?
> 

Hi Jim - sorry I didn't see this earlier...


1 - schema - think of a basic 2 table system  parent table and line items 
table... - but really all the important fields are in the child line items...
2 - mysql 5.xx
3 - sort 1st by date (all records happen 1st of every month) then product (only 
2 products needed for this)
4 - html for now
5 - for now just display and printing like:


JAN 2011
--- PRODUCT 1

data row 1
data row 2

--- PRODUCT 2

data row 3
data row 4

like that...


- thanks for checking this out




--
Thanks,
Dave - DealTek
deal...@gmail.com
[db-11]





Re: [PHP] Re: Preferred Syntax

2011-12-17 Thread Eric Butera
On Sat, Dec 17, 2011 at 12:59 AM, Adam Richardson  wrote:
> On Fri, Dec 16, 2011 at 11:53 PM, Eric Butera  wrote:
>>
>> To all the people who responded to this thread:
>> It is 2011 - please stop writing code like this.
>>
>> To the OP:
>> I'm glad you're asking questions and realizing you're not happy with
>> your current abilities and suspect there's a better way.  I've read
>> the replies in this thread and feel a bit let down.  Use a templating
>> language - yes, I understand that is what php is for - but I won't go
>> into it.  You should not be echoing, printing, or any other method of
>> concatenating html dealing with escaping quotes inside your php logic
>> code.  Please separate your concerns.
>>
>> Not sure what that means?  That's OK!  If you want to move forward,
>> look up how modern frameworks deal with this issue using their views
>> or template views.  You don't have to use a framework if you do not
>> want to, that's perfectly fine.  If it works, it works.  But in the
>> end, it the separation of logic and html is essential to code
>> maintenance.
>
>
> Eric,
>
> There are many posters to this list, and there exists a broad range of
> programming styles and abilities. I'll bet you're a competent programmer,
> and that you've worked hard to hone your craft. It takes passion and drive
> to improve one's skill set. However, I'd encourage you to focus that passion
> on the list in a way that facilitates the growth of those with questions
> whilst staying true to their current, specific needs.
>
> Frankly, every answer on the list could begin with the suggestion that they
> just use a framework. The list is here to help build up the entire skill set
> of PHP developers.
>
> Let's reexamine the original post:
>
>> Hello all.
>>
>> Can someone tell me which of the following is preferred and why?
>
>
> Use of the word "Which" implies that there were a closed set of options they
> wanted to consider, although we did offer some others, but they all stayed
> relatively true to his original options.
>
>>
>>
>>  echo "> href='/mypage.php/$page_id'>$page_name";
>>  echo "> href='/mypage.php/".$page_id."'>".$page_name."";
>
>
> Simple.
>
> Please note there is no logic anywhere in this example. PHP is truly serving
> merely as a templating language here. So, while I agree with the general
> notion that logic should not be intermingled with markup, this particular
> example does not serve as the anti-pattern you suggest.
>
> Also, note that we aren't sure where the $page_id and $page_name variables
> are coming from. In instances where these are set manually within the script
> (like a view variables at the top of the page), there's no need to escape
> anything. That said, you're right, if the data is coming from somewhere
> else, escaping should happen, but there's not enough information to infer
> that, as you say, "You should not be echoing, printing, or any other method
> of concatenating html dealing with escaping quotes inside your php
> logic code."
>
>>
>>
>> When I come across the above code in line 1, I have been changing it to
>> what you see in line 2 for no other reason than it delineates out better in
>> BBEdit.  Is this just a preference choice or is one method better than the
>> other?
>
>
> The above statement suggests there's an existing codebase that was being
> worked through. In this light, the answers mostly focused on answering the
> OP's original question, realizing that this was existing code that he was
> refactoring lightly as he goes.
>
> This is not to say that I disagree with all that you said, as I actually
> developed my own framework that:
>
> Cleanly separates PHP from HTML to avoid the intermingling of logic and
> presenation:
> http://nephtaliproject.com/documentation/markup/
> Automatically handles output escaping, input validation:
> http://nephtaliproject.com/documentation/examples/contact.php
> And lots of other features that coincide with the general focus of your
> words.
>
> Given that work, I think it's fair to say that I do agree with several of
> your general points for web development overall. However, this question
> wasn't a big picture question on how to do web development with PHP. It was
> a simple question that was answered in a helpful, specific manner by several
> on the list.
>
> Adam
>
> --
> Nephtali:  A simple, flexible, fast, and security-focused PHP framework
> http://nephtaliproject.com

Hi Adam,

Thanks for the reply, noted!  I was coming from the angle that I've
had to deal with a lot of code that is 2000 lines of
php/html/javascript inside heredocs, mixed quote escaping, etc.  I was
hoping to prevent that from becoming a new thing in this persons code
if that was the case.  Apologies for assuming.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Partner needed...

2011-12-17 Thread Don Wieland

Greetings,

I am looking for a partner to help me finish a site and share in  
profits. The site is PHP/mySQL (using jQuery and jQuery UI). A  
majority of it is finished. I need to finish up a few more modules.


The name of the site is Sport-Hub.com. I would glad to share more  
about the services the site will provide to the public, but would  
require a NDA to be signed first.


If you have interest in a potential back-end revenue stream in  
exchange for you time in coding, please contact me PRIVATELY.


Thanks!

Don Wieland
D W   D a t a   C o n c e p t s

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Fwd: [PHP] dealing with this code $_POST['custom´]

2011-12-17 Thread Marc Guay
Just forwarding Carlos' response to the list...


-- Forwarded message --
From: Carlos Sura 
Date: 17 December 2011 01:15
Subject: Re: [PHP] dealing with this code $_POST['custom´]
To: Marc Guay 




On 16 December 2011 15:57, Marc Guay  wrote:
>
> > $saving_list = $_POST['custom'] == 'FR' ? 148 : 147;
>
> Hi there, here's a quick translatation of this code that might help
> you understand it better:
>
> if ($_POST['custom'] == 'FR'){
>  $saving_list = 148;
> }
> else{
>  $saving_list = 147;
> }



Hello,

Thank you both for answer me.

Also I would like to thank you Marc Guay, because with your answer I
figured out how to do it.

My code is like this:

//$saving_list = $_POST['custom'] == 'FR' ? 148 : 147;
  if ($_POST['custom'] == 'FR'){
                $saving_list = 148;
               }
  if ($_POST['custom'] == 'EN'){
                $saving_list = 147;
               }
 else{
 $saving_list = 152;
 }

I'm not sure if that's the best way, but it is working for me as I
expected, althought any other recommendation would be great.

Regards
--
Carlos Sura.-
www.carlossura.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php