dongxiejie9387 2010-11-08 11:29 采纳率: 100%
浏览 90
已采纳

在PHP echo中嵌入javascript

echo "<td> + manuf + </td>";

Is this above ever going to work??

I'm pulling results from a mysql db to edit the contents but need the jQuery functionality to edit it, hence the embedded javascript variable...

EDIT:

Sorry for the lack of context, its related to another question i've asked on here Mysql edit users orders they have placed this is the end goal. To edit the order i place, i need to pull the results into an environment similar to how the user placed the order. So my thinking was to include the jQuery functionality to add items to a cart etc, then they could press submit and in the same way i used .Ajax to post the data to an insert php script i would post the values to an update php script! Is this backwards thinking, any advice welcomed!

  • 写回答

7条回答 默认 最新

  • dsgk40568 2010-11-08 11:48
    关注

    I suggest you take a look at the follwing.

    Now your simplest solution under you circumstances is to do go for the json_encode method. Let me show you an example:

    $json_data = array(
        'manuf' => $some_munaf_data
    );
    
    echo "<script type=\"text/javascript\">";
       echo "var Data = " . json_encode(json_data);
    echo "</script>";
    

    This will produce an object called Data, and would look like so:

    <script type="text/javascript">
    var Data = {
        munaf : "You value of $some_munaf_data"
    }
    </script>
    

    Then when you need the data just use Data.munaf and it will hold the value from the PHP Side.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?