Re: Syntax Snag need extra eyes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jul 16, 2009 at 12:25 PM, Jim Lucas <lists@xxxxxxxxx> 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('<a
> >
> href="view.php?name=$row['name']"><b>%s</b><br>%s</br><br></a>',$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(
>        '<a href="view.php?name=%s"><b>%s</b><br />%s<br /><br /></a>',
>        $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(
       '<a href="view.php?name=%1$s"><b>%1$s</b><br />%2$s<br /><br /></a>',
       $row['name'],
       $row['address']
);

Andrew

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux