Re: Problem with passing variables

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

 



Yes, the sintax is correct (if you are inside an echo or inside a print
opened with ' and not with "). ex:

echo '<a href="email.php?foo='.$myrow[3].'&?recip='.$myrow[0].' ">';    <--
correct
echo "<a href="email.php?foo='.$myrow[3].'&?recip='.$myrow[0].' ">";   <---
error !!! (parse error)

I know that you must be using the first one, but just in case ...

You can also do something different, put your html code as html not as php
code as you are doing.
This will save time, because you dont need to scape the slashes ' " , your
code will have less errors and it will run faster because the server doesnt
have to call the print or echo method from php. Example:

instead of:
<?
echo '<td><a href="email.php?recip=$myrow[0]"><img src="graphics/mail.gif"
> class="imglink" alt="Click to send mail to this person" /></a></td></tr>';
?>

use:
<td><a href="email.php?recip=<? echo $myrow[0]; ?>"><img
src="graphics/mail.gif"
 class="imglink" alt="Click to send mail to this person" /></a></td></tr>

there is a shorter way to print but i dont remeber the sintax, if you want
to know consult the php manual.
it is something like <?=$var?> i guess

This way the php sintax is reduced to its minimun.

----- Original Message -----
From: Phil Matt
To: Ricardo Lopes ; php-db@xxxxxxxxxxxxx
Sent: Tuesday, January 27, 2004 4:27 PM
Subject: Re:  Problem with passing variables


On 27 Jan 2004 at 15:56, Ricardo Lopes wrote:


> If you have something like this:
>
> echo '<td><a href="email.php?recip=$myrow[0]"><img src="graphics/mail.gif"
> class="imglink" alt="Click to send mail to this person" /></a></td></tr>';
>
> It wont work. Use instead:
>
> echo '<td><a href="email.php?recip='.$myrow[0].'"><img
> src="graphics/mail.gif" class="imglink" alt="Click to send mail to this
> person" /></a></td></tr>';
>
> Notice the '. before the $myrow[0] and the .' after, any doubt see the
> documentation about operators.
>
> This is caused because the ' doesnt parse variables to values like the "
> does.
>


Ricardo - That's it!  I did read a lot of PHP docs and mailing list posts
before I posted my question to this list, but never stumbled (and that's the
word, I'm afraid!) on the syntax explanation that would untangle this for
me.


If I want to pass additional variables for processing on the second page,
I'm assuming that the syntax would be (where $foo is another variable)


<a href="email.php?foo='.$myrow[3].'&?recip='.$myrow[0].' ">


Thanks again for restoring my sanity!


Cheers --- Phil Matt

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux