...

View Full Version : Variables in echo statement



jaguarx
09-22-2009, 09:23 AM
Hi,

I try the following PHP statements generating a button in a table cell:


echo '<td><button onclick="GetInfo($model)">'.$model.'<button></td>';

echo '<td><button onclick="GetInfo('.$model.')">'.$model.'<button></td>';

The button displays a model number on the button and passes the model number to the javascript function when being clicked.

The test results indicate neither is right. Can you please tell me the right way for this statement?

seco
09-22-2009, 09:49 AM
would help to see more code but, try that, add the


<?php { ?>

<td><button onclick="GetInfo(<?=$model;?>)"><?=$model;?><button></td>

<?php } ?>

Phil Jackson
09-22-2009, 09:59 AM
echo ''; => hello mr PHP, whatever you do, don't process this, just print it as it is.
echo ""; => hello mr PHP, process everything in side me please!



echo "<td><button onclick=\"GetInfo(".$model.")\">".$model."<button></td>";
echo "<td><button onclick=\"GetInfo(".$model.")\">".$model."<button></td>";
or
echo "<td><button onclick=\"GetInfo($model)\">$model<button></td>";
echo "<td><button onclick=\"GetInfo($model)\">$model<button></td>";
or
echo "<td><button onclick=\"GetInfo({$model})\">{$model}<button></td>";
echo "<td><button onclick=\"GetInfo({$model})\">{$model}<button></td>";

Phil Jackson
09-22-2009, 10:02 AM
not sute what this is for tho:


".$model."<button></td>";

hinch
09-22-2009, 10:02 AM
would help to see more code but, try that, add the


<?php { ?>

<td><button onclick="GetInfo(<?=$model;?>)"><?=$model;?><button></td>

<?php } ?>

using short tags is a really really BAD habit stop it :)

<?= <?php echo

not all hosts support short tags and they can cause nightmare problems later on

abduraooft
09-22-2009, 10:04 AM
Or like
echo "<td><button onclick=\"GetInfo('{$model}');\">{$model}<button></td>

<td><button onclick=\"GetInfo('{$model}');\">$model<button></td>";

jaguarx
09-22-2009, 10:23 AM
Oh, The last <button> should be </button>. Thanks for all thr great help.


Warren



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum