简体   繁体   中英

How do I pass SELECT PHP to Javascript?

I am new to PHP. Please advise me on how to use PHP in Javascript. My 1st Code sys_out_currency to put in the second code USD: 0.2493,

1st Code

<?php
$sql = mysql_query("SELECT * FROM sys_currency_buy");
while($row = mysql_fetch_array($sql)) {
?> 
<p><?php echo $row['sys_out_currency']; ?></p>
<p><?php echo $row['sys_in_currency']; ?></p>
<?php } ?>

2nd Code

<script>
var MYRrates = {
USD: 0.2493, 
SGD: 0.3355, 
GBP: 0.1908, 
EUR: 0.2247, 
AUD: 0.3663, 
NZD: 0.3802, 
CAD: 0.3257, 
CHF: 0.2421, 
HKD: 1.94, 
CNY: 1.72, 
NT: 7.54, 
THB: 7.57,   
PHP: 13.33, 
INR: 18.34, 
SAR: 0.94, 
JPY: 273.9,   
KRW: 295.8, 
VND: 5700, 
IDR: 3400,     
};

This is the way how you can use PHP inside javascript :

<script type='text/javascript'>
    function test() {
        alert("<?php echo "Testing"; ?>");
    }
    test();// to call the function
</script> 

PHP in JavaScript code can't be called. But JavaScript code can be called in PHP. You can use AJAX call for this purpose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM