Re: [PHP] Syntax Snag need extra eyes

2009-07-16 Thread Jim Lucas
Bastien Koert wrote:
> On Thu, Jul 16, 2009 at 12:43 PM, Andrew Ballard wrote:
>> On Thu, Jul 16, 2009 at 12:35 PM, Jim Lucas  wrote:
>>> Andrew Ballard wrote:
 On Thu, Jul 16, 2009 at 12:25 PM, Jim Lucas  wrote:
>> [snip]
> Also, this is the wrong way to use printf().  Please go read the manual
> page for this function.
>
> Try:
>
> printf(
>'%s%s',
>$row['name'],
>$row['name'],
>$row['address']
> );
>
> This is the correct way to use printf()
>
>
>
 I like this, just because I don't need to repeat $row['name'] (but it is 
 the
 same thing):

 printf(
'%1$s%2$s>>> />',
$row['name'],
$row['address']
 );

 Andrew

>>>
>>> I was wondering if that was possible.
>>>
>>> Thanks for the tip.
>>>
>>> Jim Lucas
>>>
>> That's what I like about this list. I wasn't totally sure it would
>> work myself, but I was pretty sure it would, and this was another one
>> of those posts that provided just enough prompting for me to actually
>> pop the code into Zend Studio where I could test it pretty quickly.
>> :-)
>>
>> Andrew
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
> 
> another option is to wrap the array elements in curly braces
> 
> printf(' href="view.php?name={$row['name']}">%s%s',$row['name']
> ,$row['address']);
> 

No, that won't work.  The string that it is in, was created using single
quotes.  Therefor the array reference will never be looked at.  It will
simply print the actuall string, not the value associated to the array
reference.

Jim Lucas


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



Re: [PHP] Syntax Snag need extra eyes

2009-07-16 Thread Bastien Koert
On Thu, Jul 16, 2009 at 12:43 PM, Andrew Ballard wrote:
> On Thu, Jul 16, 2009 at 12:35 PM, Jim Lucas  wrote:
>>
>> Andrew Ballard wrote:
>> > On Thu, Jul 16, 2009 at 12:25 PM, Jim Lucas  wrote:
> [snip]
>> >> Also, this is the wrong way to use printf().  Please go read the manual
>> >> page for this function.
>> >>
>> >> Try:
>> >>
>> >> printf(
>> >>        '%s%s',
>> >>        $row['name'],
>> >>        $row['name'],
>> >>        $row['address']
>> >> );
>> >>
>> >> This is the correct way to use printf()
>> >>
>> >>
>> >>
>> > I like this, just because I don't need to repeat $row['name'] (but it is 
>> > the
>> > same thing):
>> >
>> > printf(
>> >        '%1$s%2$s> > />',
>> >        $row['name'],
>> >        $row['address']
>> > );
>> >
>> > Andrew
>> >
>>
>>
>> I was wondering if that was possible.
>>
>> Thanks for the tip.
>>
>> Jim Lucas
>>
>
> That's what I like about this list. I wasn't totally sure it would
> work myself, but I was pretty sure it would, and this was another one
> of those posts that provided just enough prompting for me to actually
> pop the code into Zend Studio where I could test it pretty quickly.
> :-)
>
> Andrew
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

another option is to wrap the array elements in curly braces

printf('%s%s',$row['name']
,$row['address']);

-- 

Bastien

Cat, the other other white meat

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



Re: [PHP] Syntax Snag need extra eyes

2009-07-16 Thread Andrew Ballard
On Thu, Jul 16, 2009 at 12:35 PM, Jim Lucas  wrote:
>
> Andrew Ballard wrote:
> > On Thu, Jul 16, 2009 at 12:25 PM, Jim Lucas  wrote:
[snip]
> >> Also, this is the wrong way to use printf().  Please go read the manual
> >> page for this function.
> >>
> >> Try:
> >>
> >> printf(
> >>        '%s%s',
> >>        $row['name'],
> >>        $row['name'],
> >>        $row['address']
> >> );
> >>
> >> This is the correct way to use printf()
> >>
> >>
> >>
> > I like this, just because I don't need to repeat $row['name'] (but it is the
> > same thing):
> >
> > printf(
> >        '%1$s%2$s',
> >        $row['name'],
> >        $row['address']
> > );
> >
> > Andrew
> >
>
>
> I was wondering if that was possible.
>
> Thanks for the tip.
>
> Jim Lucas
>

That's what I like about this list. I wasn't totally sure it would
work myself, but I was pretty sure it would, and this was another one
of those posts that provided just enough prompting for me to actually
pop the code into Zend Studio where I could test it pretty quickly.
:-)

Andrew

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



Re: [PHP] Syntax Snag need extra eyes (RESOLVED)

2009-07-16 Thread Jim Lucas
Miller, Terion wrote:
> Thanks Jim!! I did read the manual and don't get it, like why is printf used 
> and not echo...how do you decided which to use?
> 
> 
> 
> On 7/16/09 11:25 AM, "Jim Lucas"  wrote:
> 
> printf(
> '%s%s',
> $row['name'],
> $row['name'],
> $row['address']
> );
> 

I would say personal preference is the main factor.

I use echo mostly.  Some people like print() and some line printf() &
sprintf().  Probably depends mostly on where you learned to program.

Honestly, echo and print() use the same internal PHP construct.  From
what I understand, one links to the other as an alias or something to
that affect.  Also, the parenthesis are optional when using echo and print.

Back in the day, to be consistent, most people used printf() in C or
other similar programming languages.

Jim Lucas


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



Re: [PHP] Syntax Snag need extra eyes

2009-07-16 Thread Jim Lucas
Andrew Ballard wrote:
> On Thu, Jul 16, 2009 at 12:25 PM, Jim Lucas  wrote:
> 
>> Miller, Terion wrote:
>>> I'm almost there with my little pagination script but now I'm hung on the
>>> "Unexpected T_Variable" error...which in the past has been a semi-colon
>>> missing so I'm not sure why this is throwing it...eyes please:
>>>
>>>  printf('>>
>> href="view.php?name=$row['name']">%s%s',$row['name']
>>> ,$row['address']);
>>>
>>>
>> The single ticks in your array() variable is causing the problem.
>>
>> plus, since you are using single quotes for the entire string, the
>> variable isn't going to be interpreted as a variable.  It will simply
>> print the string $row['name']
>>
>> Also, this is the wrong way to use printf().  Please go read the manual
>> page for this function.
>>
>> Try:
>>
>> printf(
>>'%s%s',
>>$row['name'],
>>$row['name'],
>>$row['address']
>> );
>>
>> This is the correct way to use printf()
>>
>>
>>
> I like this, just because I don't need to repeat $row['name'] (but it is the
> same thing):
> 
> printf(
>'%1$s%2$s',
>$row['name'],
>$row['address']
> );
> 
> Andrew
> 


I was wondering if that was possible.

Thanks for the tip.

Jim Lucas


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



Re: [PHP] Syntax Snag need extra eyes

2009-07-16 Thread Andrew Ballard
On Thu, Jul 16, 2009 at 12:25 PM, Jim Lucas  wrote:

> Miller, Terion wrote:
> > I'm almost there with my little pagination script but now I'm hung on the
> > "Unexpected T_Variable" error...which in the past has been a semi-colon
> > missing so I'm not sure why this is throwing it...eyes please:
> >
> >  printf(' >
> href="view.php?name=$row['name']">%s%s',$row['name']
> > ,$row['address']);
> >
> >
>
> The single ticks in your array() variable is causing the problem.
>
> plus, since you are using single quotes for the entire string, the
> variable isn't going to be interpreted as a variable.  It will simply
> print the string $row['name']
>
> Also, this is the wrong way to use printf().  Please go read the manual
> page for this function.
>
> Try:
>
> printf(
>'%s%s',
>$row['name'],
>$row['name'],
>$row['address']
> );
>
> This is the correct way to use printf()
>
>
>
I like this, just because I don't need to repeat $row['name'] (but it is the
same thing):

printf(
   '%1$s%2$s',
   $row['name'],
   $row['address']
);

Andrew


Re: [PHP] Syntax Snag need extra eyes (RESOLVED)

2009-07-16 Thread Miller, Terion
Thanks Jim!! I did read the manual and don't get it, like why is printf used 
and not echo...how do you decided which to use?



On 7/16/09 11:25 AM, "Jim Lucas"  wrote:

printf(
'%s%s',
$row['name'],
$row['name'],
$row['address']
);


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



Re: [PHP] Syntax Snag need extra eyes

2009-07-16 Thread Jim Lucas
Miller, Terion wrote:
> I'm almost there with my little pagination script but now I'm hung on the
> "Unexpected T_Variable" error...which in the past has been a semi-colon
> missing so I'm not sure why this is throwing it...eyes please:
> 
>  printf(' href="view.php?name=$row['name']">%s%s',$row['name']
> ,$row['address']);
> 
> 

The single ticks in your array() variable is causing the problem.

plus, since you are using single quotes for the entire string, the
variable isn't going to be interpreted as a variable.  It will simply
print the string $row['name']

Also, this is the wrong way to use printf().  Please go read the manual
page for this function.

Try:

printf(
'%s%s',
$row['name'],
$row['name'],
$row['address']
);

This is the correct way to use printf()


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



RE: [PHP] Syntax Snag need extra eyes

2009-07-16 Thread Bob McConnell
From: Miller, Terion

> I'm almost there with my little pagination script but now I'm hung on
the
> "Unexpected T_Variable" error...which in the past has been a
semi-colon
> missing so I'm not sure why this is throwing it...eyes please:
> 
>  printf('
href="view.php?name=$row['name']">%s%s',$row['na
me']
> ,$row['address']);

It looks like you have nested single quotes. You probably need to escape
the inside set.

Bob McConnell

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